<分区>
好的,所以我一直在搜索此站点以找到解决我的问题的方法。我找到了一个,但出于某种原因,代码无法按预期方式工作。我的目标是拥有一个包含部分的表格 View 。在每个部分下是每个部分中不同数量的单元格(例如一个部分中有 1 个单元格,另一个部分中有 3 个单元格)。
这是我的代码
import UIKit
class cat1: UIViewController, UITableViewDelegate, UITableViewDataSource {
let proc = [["this"], ["Ye", "it", "will"]]
let infor = [["info 1"] , ["info 3", "info 2" , "info 4"]]
let arrayforsec = [ "test", "testtt"]
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return proc[section].count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell1", for: indexPath) as UITableViewCell
let cellText = proc[indexPath.section][indexPath.row]
let descriptiontxt = infor[indexPath.section][indexPath.row]
cell.detailTextLabel?.numberOfLines = 0
cell.detailTextLabel?.lineBreakMode = .byWordWrapping
cell.textLabel?.text = cellText
cell.detailTextLabel?.text = descriptiontxt
return (cell)
}
func tableView(_ tableView: UITableView, titleForHeaderInSection section :Int) -> String?{
return arrayforsec[section]
}
func numberOfSectionsInTableView(in tableView: UITableView) -> Int {
return proc.count
}
}
我的目标是有 2 个不同的 header ,test 和 testtt
测试将有标题为 this 和副标题信息为 1 的单元格,依此类推
我搞砸了什么?
这里是我咨询的解决方案:How do I populate two sections in a tableview with two different arrays using swift?
(有 40 个赞成票的回应)