2016-12-25 35 views
0

我试图在Swift 3中创建一个非常简单的索引tableView。 我设法将索引添加到视图中,但只要我添加了节标题,每个单元格显示一个奇怪的分隔线在右侧(see screenshotuitableview单元格中有一个横向分隔符

我不知道它来自哪里,它不会出现在我在网上看到的其他索引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 
    } 
} 

我能做什么呢?

谢谢

回答

0

我相信你需要注释掉或删除下面的委托函数。

override func tableView(_ tableView: UITableView, sectionForSectionIndexTitle title: String, at index: Int) -> Int 
    { 
     let temp = indexOfNumbers as NSArray 
     return temp.index(of: title) 
    } 
相关问题