你好是新來的,所以我有這種類型的多維數組如何創建多節的tableView
[["name1","name2"],["name3,"name4"],["name5","name6"]]
的,我想創建多個部分的UITableView的
let tableView: UITableView = {
let table = UITableView()
return table
}()
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .white
tableView.delegate = self
tableView.dataSource = self
tableView.register(TableCell.self, forCellReuseIdentifier: "tablecell")
view.addSubview(tableView)
view.addConstraintsWithFormat("H:|[v0]|", views: tableView)
view.addConstraintsWithFormat("V:|[v0]|", views: tableView)
}
override func viewDidAppear(_ animated: Bool) {
print("Groups are \(allGroups.count)")
print(allGroups[0].count)
}
func numberOfSections(in tableView: UITableView) -> Int {
return allGroups.count
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return allGroups[section].count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "tablecell") as! TableCell
for i in allGroups{
cell.textLabel?.text = i[indexPath.row]
for j in i{
print(j)
}
}
return cell
}
func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return "Section \(section)"
}
func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let vw = UIView()
vw.backgroundColor = UIColor.gray
return vw
}
}
這裏是什麼我的代碼目前看起來像但每個部分都出現相同的數據
你有什麼迄今所做?告訴我們你的代碼:-) –
我堅持我不知道如何訪問數組用於我的代表,就像我不能計數'numberOfRowsInSection'或'numberOfSections' –
@Johnmayowa用代碼編輯你的問題,你目前正在嘗試, –