【问题标题】:How to Index a UITable with no sections at all如何索引没有部分的 UITable
【发布时间】:2015-03-10 13:10:48
【问题描述】:

是否可以(或不可能)为没有任何节的表编制索引?

【问题讨论】:

  • 您可以将numberOfRowsInSectionnumberOfSectionsInTableView 的返回值交换,并在其他地方使用[indexPath.section] 而不是indexPath.row

标签: ios uitableview swift indexing


【解决方案1】:

据我所知,除了语法之外,swift 没有任何变化:

/* section headers
   appear above each `UITableView` section */
override func tableView(tableView: UITableView,
    titleForHeaderInSection section: Int)
    -> String {
    // do not display empty `Section`s
    if !self.sections[section].users.isEmpty {
        return self.collation.sectionTitles[section] as String
    }
    return ""
}

/* section index titles
   displayed to the right of the `UITableView` */
override func sectionIndexTitlesForTableView(tableView: UITableView)
    -> [AnyObject] {
    return self.collation.sectionIndexTitles
}

override func tableView(tableView: UITableView,
    sectionForSectionIndexTitle title: String,
    atIndex index: Int)
    -> Int {
    return self.collation.sectionForSectionIndexTitleAtIndex(index)
}

Full example here.

【讨论】:

    猜你喜欢
    • 2023-03-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多