ViewController中的GroupTable与Swift 3
问题描述:
我把表在我的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”。
它确实不显示“面粉”,“蛋糕面粉”。
我不知道问题出在哪里。请帮帮我。
答
方法numberOfSectionsInTableView
是错误的,默认值为1
雨燕3语法是:
func numberOfSections(in tableView: UITableView) -> Int {
return TableArray.count
}
根据命名规则变量名必须以小写字母开头。
是bro @vadian。但是,我想要2个部分。一节包括 - >“家”,“苹果”,“橙”,“菠萝”。第二部分包括 - >“面粉”,“蛋糕面粉”。我怎样才能做到这一点? bro –
您正在使用错误的API。用我的答案中的方法替换你的方法。 – vadian
Bro @vadian,你的代码适合我...感谢百万兄弟! :) :) :) –