2016-12-25 2 views
0

私はSwift 3で非常に単純なインデックス付きテーブルビューを作成しようとしています。 ビューにインデックスを追加することはできましたが、セクションヘッダーを追加するとすぐに、 (see screenshotuitableviewセルに横方向の区切りがあります

私はそれがどこから来たのかわからず、私はオンラインで見た他のインデックス付きのテーブルビューのチュートリアルには表示されません。

これは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) 
    } 
関連する問題