【发布时间】:2016-12-25 23:08:20
【问题描述】:
我正在尝试在 Swift 3 中创建一个非常简单的索引 tableView。 我设法将索引添加到视图中,但是一旦我添加了节标题,每个单元格的右侧都会显示一条奇怪的分隔线(see screenshot)
我不知道它可能来自哪里,并且它没有出现在我在网上看到的其他索引 tableview 教程中。
这是 TableViewController 的代码:
class TableViewController: UITableViewController
{
var tableData : [String] = []
var indexOfNumbers : [String] = []
override func viewDidLoad()
{
super.viewDidLoad()
let numbers = "100 200 300 400 500 600 700 800 900 1000 1100 1200 1300 1400 1500"
tableData = numbers.components(separatedBy: " ")
let indexes = "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15"
indexOfNumbers = indexes.components(separatedBy: " ")
}
override func numberOfSections(in tableView: UITableView) -> Int { return indexOfNumbers.count }
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return 1 }
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
{
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
cell.textLabel?.text = tableData[indexPath.section]
print(indexPath.section, indexPath.row, separator : " ")
return cell
}
override func tableView(_ tableView: UITableView, sectionForSectionIndexTitle title: String, at index: Int) -> Int
{
let temp = indexOfNumbers as NSArray
return temp.index(of: title)
}
override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String?
{
return "Section \(section)"
}
override func sectionIndexTitles(for tableView: UITableView) -> [String]?
{
return indexOfNumbers
}
}
我能做什么?
谢谢
【问题讨论】:
标签: ios swift uitableview swift3 xcode8