我正在尝试制作一个按字母顺序排列的滚动条,就像联系人和 Apple Music 中的滚动条一样。但是,当我调用sectionIndexTitlesForTableView
方法时,不显示按字母顺序排列的滚动条。我该如何解决?我参考了这个较旧的教程和较新的教程。
代码
class SongsViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
private var sectionTitles = ["A", "B", "C"]
func sectionIndexTitlesForTableView(tableView: UITableView) -> [AnyObject]! {
return sectionTitles as [AnyObject]
}
func tableView(_ tableView: UITableView, sectionForSectionIndexTitle title: String, at index: Int) -> Int {
return sectionTitles.index(of: title)!
}
}
您的教程适用于早期版本的 Swift。当前的函数签名是:
func sectionIndexTitles(for tableView: UITableView) -> [String]? {
return sectionTitles
}
func tableView(_ tableView: UITableView, sectionForSectionIndexTitle title: String, at index: Int) -> Int {
return sectionTitles.index(of: title)!
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句