TableViewController仅显示一个动态部分

时间:2016-10-11 10:57:14

标签: swift xcode uitableview

出于某种原因,即使我尝试过从3个不同的教程复制的代码,我也无法获得更多,然后在表格中出现一个部分。我已经玩了几个小时,但我找不到问题。

我已正确设置tableCell标识符,甚至在一个新项目中尝试从一开始就完成所有操作,但没有运气。我使用的代码如下,我试图使其工作时硬编码的部分和行数,但情况并非如此。

import UIKit

class multiTableViewController: UITableViewController {

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 viewDidLoad() {
    super.viewDidLoad()
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

override func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {       
    return self.section[section]
}

 func numberOfSections(in tableView: UITableView) -> Int {
    return 3
}

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return 3
}


override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("tableCell", forIndexPath: indexPath)

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

    return cell

}
}

在这种情况下,表格会显示部分标题" pizza"和三个相应的项目,但不是接下来的三个部分。

1 个答案:

答案 0 :(得分:3)

替换您的func numberOfSections(in tableView: UITableView) -> Int {

由下面的一个: -

 func numberOfSectionsInTableView(tableView: UITableView) -> Int {}
相关问题