2016-11-21 10 views
-1

我有一個示例代碼,但每段的行不會顯示,因爲numberOfRowsInSection不再存在於SWIFT 3中。如何在SWIFT 3中執行對UITableView的剖面和單元格的動態創建

我目前擁有的FF代碼:

let section = ["pizza", "deep dish pizza", "calzone"] 

let items = [["Margarita", "BBQ Chicken", "Pepperoni"], ["sausage", "meat lovers", "veggie lovers"], ["sausage", "chicken pesto", "prawns", "mushrooms"]] 

override func tableView(_ tableView: UITableView, titleForFooterInSection section: Int) -> String? { 

    return self.section[section] 

} 

override func numberOfSections(in tableView: UITableView) -> Int { 
    return self.section.count 
} 

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
    let cell = tableView.dequeueReusableCell(withIdentifier: "tableCell", for: indexPath) 

    // Configure the cell... 

    cell.textLabel?.text = self.items[indexPath.section][indexPath.row] 

    return cell 
} 

結果:

enter image description here

有人可以顯示更新swift 3正確的代碼?謝謝!

+0

你沒有它你的代碼示例中,你有沒有實施'numberOfRowsInSection'? – Wes

+0

我做過了,但是xcode突出顯示爲紅色,表示它是未知的,但在tableView工作之前添加_。<。謝謝! – ReversedcigoL

回答

3

爲了您的信息numberOfRowsInsectionswift3存在,請參閱下面

override func numberOfSections(in tableView: UITableView) -> Int { 
    return section.count 
} 

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
    return items[section].count 
} 

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
    let cell = tableView.dequeueReusableCell(withIdentifier: "Cell") 
    cell?.textLabel?.text = items[indexPath.section][indexPath.row] 
    return cell! 
} 

謝謝:)

+0

早些時候,我認爲'numberOfRowsInSection'被刪除,因爲xcode突出顯示它是紅色的,說它是未知的,也沒有在tableview的intellisense中看到任何'numberOfRowsInSection',但在表視圖中添加了__。謝謝! – ReversedcigoL

+0

精緻快樂編碼:) –

相關問題