【发布时间】:2015-09-26 13:02:30
【问题描述】:
我正在 UITableView 中加载联系人,我想在右端添加索引,以便用户浏览联系人。
我正在使用代码:
var indexOfNames = [String]()
let indexNames = "A B C D E F G H I J K L M N O P Q R S T U V W X Y Z"
indexOfNames = indexNames.componentsSeparatedByString(" ")
func sectionIndexTitlesForTableView(tableView: UITableView) -> [String]? {
return indexOfNames
}
func tableView(tableView: UITableView, sectionForSectionIndexTitle title: String, atIndex index: Int) -> Int {
let temp = indexOfNames as NSArray
return temp.indexOfObject(title)
}
但它不起作用。当我点击索引时,表格视图会出现在第一行。即A。我已经为 tableview 设置了代表。也许 Swift 2.0 有一些问题?
【问题讨论】:
-
temp.indexOfObject(title)返回什么值?您的表格是否有 26 个部分,所有部分都有行? -
temp.indexOfObject(title)是所有行数据的索引。即 A、B、C ......并且不,我没有 26 个部分。但我不知道如何编码 -
我的问题实际上是关于您作为索引返回的数字是否实际上与表格可以合理转到的某个部分匹配。
-
不,我不这么认为。
标签: ios swift uitableview swift2