2017-02-28 74 views
0

我把在我的ViewController。我做了GroupTable。所以,我选择表格并在属性检查器中选择样式“分组”。ViewController中的GroupTable与Swift 3

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”。
它确实不显示“面粉”,“蛋糕面粉”。
我不知道问题出在哪里。请帮帮我。

回答

1

方法numberOfSectionsInTableView是错误的,默认值为1

雨燕3语法是:

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

根据命名规则变量名必须以小写字母开头。

+0

是bro @vadian。但是,我想要2个部分。一节包括 - >“家”,“苹果”,“橙”,“菠萝”。第二部分包括 - >“面粉”,“蛋糕面粉”。我怎样才能做到这一点? bro –

+0

您正在使用错误的API。用我的答案中的方法替换你的方法。 – vadian

+0

Bro @vadian,你的代码适合我...感谢百万兄弟! :) :) :) –