我想要为联系人表视图添加一些部分标题。我有一个联系人列表,可能像这样:Array
:
Bill Apple
Borat
Steve Test
我已经添加了以下内容:
func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
let currentCollation = UILocalizedIndexedCollation.currentCollation() as UILocalizedIndexedCollation
let sectionTitles = currentCollation.sectionTitles as NSArray
return sectionTitles.objectAtIndex(section) as? String
}
func sectionIndexTitlesForTableView(tableView: UITableView) -> [String]? {
let currentCollation = UILocalizedIndexedCollation.currentCollation() as UILocalizedIndexedCollation
return currentCollation.sectionIndexTitles as [String]
}
func tableView(tableView: UITableView, sectionForSectionIndexTitle title: String, atIndex index: Int) -> Int {
let currentCollation = UILocalizedIndexedCollation.currentCollation() as UILocalizedIndexedCollation
return currentCollation.sectionForSectionIndexTitleAtIndex(index)
}
这将显示A-Z标题。然而,由于只有一个部分和一个数组存储联系人,实际功能无法正常工作。
我们应该将
Array
按字母顺序排序为字母顺序Array
吗?以便它具有多个部分?还是有更简单的方法来解决这个问题?