gpt4 book ai didi

ios - sectionForSectionIndexTitle 和 sectionIndexTitlesForTableView 未在 swift 3 中调用

转载 作者:搜寻专家 更新时间:2023-11-01 05:56:05 30 4
gpt4 key购买 nike

我在项目中使用了联系簿,所有数据显示为 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/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com