0

我把Table放在我的ViewController中。我制作了 GroupTable。所以,我选择表格并在属性检查器中 选择“分组”样式。

 var TableArray = [["Home","Apple","Orange","Pineapple"],["Flour","Cake Flour"]] 

 func numberOfSectionsInTableView(tableView: UITableView) -> Int {

    return TableArray.count

}

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

    debugPrint(TableArray[section].count)

    return TableArray[section].count

}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

    let cell = tableView.dequeueReusableCell(withIdentifier: TableArray[indexPath.section][indexPath.row], for: indexPath) as UITableViewCell

    cell.imageView?.image = menuIconImage[indexPath.row]
    cell.textLabel?.text = TableArray[indexPath.section][indexPath.row]
    cell.selectionStyle = UITableViewCellSelectionStyle.blue
    tableView.rowHeight = 56.0;

    return cell

} 

当我运行应用程序时,表格只显示“Home”、“Apple”、“Orange”、“Pineapple”。
它不显示“面粉”、“蛋糕面粉”。
我不知道问题出在哪里。请帮我。

4

1 回答 1

1

方法numberOfSectionsInTableView错误,默认值为1。

Swift 3 的语法是:

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

根据命名约定,变量名应以小写字母开头。

于 2017-02-28T09:25:04.100 回答