2017-08-07 20 views
2

在我的viewController与tableView在其中我有使用fetchedResultsController从核心数据数据库中获取的对象的列表。我按部分对所有提取的结果进行了分组。它工作正常,我已经实现了以下方法来启用它出现在TableView中的右侧AZ sectionIndexes:sectionIndexTitles(用于tableView:UITableView)方法返回奇怪的结果

func sectionIndexTitles(for tableView: UITableView) -> [String]? { 
    let indexTitles = self.fetchedResultsController.sectionIndexTitles 

     return indexTitles 

    } 

    func tableView(_ tableView: UITableView, sectionForSectionIndexTitle title: String, at index: Int) -> Int { 
     return self.fetchedResultsController.section(forSectionIndexTitle: title, at: index) 
    } 

我也有fetchedResultsController

var fetchedResultsController: NSFetchedResultsController<Object>! 

self.fetchedResultsController = NSFetchedResultsController(fetchRequest: fetchRequest, managedObjectContext: context!, sectionNameKeyPath: "project.group.name", cacheName: nil) 

sectionIndexTitles这个声明能正常工作,而我在我的Core Data数据库中有英文group.name的值,但是当我在另一种语言中使用group.name值时(或英文与英文混合)sectionIndexTitles显示(返回)我的英文字母,但对于非英文字母返回问号或英文字母。

例如它返回像这样的数组["A", "B", "F", "G", "R", "S", "A", "E"],而不是像这样["A", "B", "F", "G", "R", "S", "Letter in another language", "Letter in another language"]返回数组。 我已更改语言方案,并返回["A", "B", "F", "G", "R", "S", "?", "?"]。 它用英文字母替代非英文字母或显示“?”,而不是用另一种语言显示价值。

enter image description here

不知道这是一个错误吗?或者,也许它不能以不同的语言显示字母。哪里可以解决问题以及如何解决?

我正在使用Swift 3,Xcode 8.3.3。

回答

0

我面临同样的问题,对于俄语它回报了我!而不是字符。所以,我执行此解决方案:

override func sectionIndexTitles(for tableView: UITableView) -> [String]? { 
    if let sections = fetchedResultsController?.sections { 
     var sectionTitles: [String] = [] 

     for section in sections { 
      sectionTitles.append(String(describing: section.name.first!)) 
     } 
     return sectionTitles 
    } 

return fetchedResultsController?.sectionIndexTitles 
} 

我认为这是可以用于大多数情况下