【问题标题】:Event generation on selection of Alphabetical sections in table table view in swiftswift中在表格视图中选择字母部分的事件生成
【发布时间】: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


【解决方案1】:

当用户点击章节索引标题时,您无法处理直接事件,但您可以实现的是

optional func tableView(_ tableView: UITableView, 
  sectionForSectionIndexTitle title: String, 
                           at index: Int) -> Int

在数据源上调用此方法并将节索引标题转换为表视图中的节。这通常在用户点击索引中的条目时调用。

【讨论】:

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