【问题标题】:sectionForSectionIndexTitle and sectionIndexTitlesForTableView Not called in swift 3sectionForSectionIndexTitle 和 sectionIndexTitlesForTableView 未在 swift 3 中调用
【发布时间】:2017-06-09 12:07:12
【问题描述】:

我在项目中使用了联系人 Book,所有数据显示为 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 sectionIndexTitles(for tableView: UITableView) -> [String]?

标签: ios iphone swift swift3


【解决方案1】:

如下所示更改部分方法

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 数据源和委托与相应的类连接
  • 如果您想要多个部分,请确保您在代码中为 tableView 数据源方法提供了部分的数量。

【讨论】:

  • 嘿巴拉,我尝试了你给定的代码,但它不起作用。我还设置了 tableview 数据源和委托,但没有调用方法。任何其他建议或想法请帮助我。
  • 检查您的 TableView 委托和数据源是否与类连接
  • 你好,bala,我检查了它是否已连接到班级。
【解决方案2】:

确保您的委托和 TableView 的数据源 并使用断点进行调试

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-06-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-06
    • 2018-02-10
    • 1970-01-01
    相关资源
    最近更新 更多