【发布时间】:2020-05-08 14:19:42
【问题描述】:
我从 Web 服务获取一些联系人,我需要在表格视图中按字母顺序显示它们以及按字母顺序排列的部分。这部分完成了。
截图:
问题是,对于某些逻辑实现,我实际上需要识别用户从字母部分选择的字母。我找不到任何 tableView 的委托方法可以识别何时在字母部分中选择了字母。
我已经实现的方法:
1) func sectionIndexTitles(for tableView: UITableView) -> [String]? {}
2) func numberOfSections(in tableView: UITableView) -> Int {} and other mandatory tableview services.
是有委托方法,或者在选择一个字母表时生成事件的方法?
【问题讨论】:
-
正如@Andreas Oetjen 所说,您可以使用
func tableView(_ tableView: UITableView, sectionForSectionIndexTitle title: String, at index: Int) -> Int { if let index = sections.firstIndex(where: { $0 == title }) { return index } return 0 }获取索引
标签: ios swift iphone uitableview