我在项目中使用了联系簿,所有数据显示为 sectionWise。Tableview 部分索引不显示该实现 sectionForSectionIndexTitle 和 sectionIndexTitlesForTableView 但不调用。
为此,我使用了以下代码:
let arrIndexSection = ["A","B","C","D", "E", "F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
func tableView(_ tableView: UITableView, sectionForSectionIndexTitle title: String, at index: Int) -> Int
{
return ([UITableViewIndexSearch] + UILocalizedIndexedCollation.current().sectionIndexTitles as NSArray).index(of: title) - 1
}
func sectionIndexTitlesForTableView(tableView: UITableView) -> [AnyObject]!
{
return arrIndexSection as [AnyObject]
}
任何人对上述解决方案有想法或解决方案,请帮助我。
谢谢。
最佳答案
更改部分方法如下所示
func numberOfSections(in tableView: UITableView) -> Int {
return arrIndexSection.count
}
func sectionIndexTitles(for tableView: UITableView) -> [String]? {
return arrIndexSection
}
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 44
}
检查以下几点
- 检查与您的 tableview 连接的 tableView IBOutlet。
- 确保您的 tableview 数据源和委托(delegate)已连接到相应的类
- 如果您想要多个部分,请确保您在代码中为 tableView 数据源方法提供了部分的数量。
关于ios - sectionForSectionIndexTitle 和 sectionIndexTitlesForTableView 未在 swift 3 中调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44457427/