【发布时间】:2021-03-26 18:14:14
【问题描述】:
我的第一部分中已经有了单元格,但我不知道如何将我的 cell2 专门放在我的第二部分中:
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if section == 0 {
return 4
}
if section == 1 {
return pushUpArray.count
}
return section
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
var cell = UITableViewCell(style: .value1, reuseIdentifier: "section1")
var cell2 = UITableViewCell(style: .value1, reuseIdentifier: "section2")
if cell == nil {
cell = UITableViewCell(style: .value1, reuseIdentifier: "section1")
cell.textLabel?.font = UIFont.boldSystemFont(ofSize: 20)
cell.textLabel?.text = TableViewValues[indexPath.row]
cell.detailTextLabel?.text = TableViewDetailValues[indexPath.row]
}
if cell2 == nil {
cell2 = UITableViewCell(style: .value1, reuseIdentifier: "section2")
}
cell2.textLabel?.font = UIFont.boldSystemFont(ofSize: 20)
cell2.textLabel?.text = "\(indexPath.row). Count: \(count) Time: \(Time)"
return cell
return cell2
}
提前致谢!
【问题讨论】:
-
你可以检查像“indexPath.section == 0”而不是“cell2 == nil”只是更新你的条件
标签: swift uitableview uitabbarcontroller sections