ios - UITableView sectionForSectionIndexTitle 从未在 swift 3 中调用

标签 ios uitableview indexing swift3 xcode8.1

enter image description here

由于我是 Swift 的新手,所以我陷入了困境。我正在开发一个应用程序,我想在其中显示侧面索引部分,就像在联系人应用程序中一样。我在我的应用程序中使用了此代码

func tableView(_ tableView: UITableView, sectionForSectionIndexTitle title: String, at index: Int) -> Int{
     print(sections.index(of:title)!)
     return sections.index(of:title)!
 }

但是这个方法永远不会被调用,并且 TableView 没有显示侧面索引部分。我正在使用 Swift 3。任何帮助将不胜感激。

我有一个表格 View ,现在在哪个国家/地区列表中我想通过选择部分索引(A..Z)来关注特定部分。我已经实现了上面的代码,但没有显示部分索引。

最佳答案

经过长时间的研究得到了解决方案,我犯了一个愚蠢的错误。要专注于选定部分,我们需要使用此代码在选定部分滚动 tableView。

你可以在这里看到完整的代码:https://github.com/ipraba/EPContactsPicker/blob/master/Pods/EPContactsPicker.swift

override open func tableView(_ tableView: UITableView, sectionForSectionIndexTitle title: String, at index: Int) -> Int {
          //  if resultSearchController.isActive { return 0 }
            tableView.scrollToRow(at: IndexPath(row: 0, section: index), at: UITableViewScrollPosition.top , animated: false)
            return sections.index(of: title)!
        }

关于ios - UITableView sectionForSectionIndexTitle 从未在 swift 3 中调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41264032/

相关文章:

ios - 连接到 iTunes 以使用推送通知

ios - TableView 原型(prototype)单元格中的 Collection View

iphone - 检测 UITableView 是否滚动到底部时出现问题

regex - 我可以对索引子文档字段执行 MongoDB "starts with"查询吗?

solr - 使用 Solr 处理变音符号和重音符号

ios - 如何快速在特定表格 View 行执行特定操作?

ios - 将 UIImage 数组导出到视频 - 蓝色结果

c# - 如何使用 segue 传递对象

ios - 如何从 soap 加载数组并显示在 TableView 上?

indexing - Apache Solr - 文档本身除了索引之外还存储在内部吗?