我试图用两个部分实现tableview。每个部分都有一种需要的单元格。来自不同部分的TableView单元混合起来
因此,第一节单元被划分为PendingTVC 第二节单元被划分为ScheduledCell。
我有以下方法实施,但细胞越来越混合。例如,如果第一部分有3个单元格,则第2部分中的前3个单元格具有与第1部分的前3个单元格相关的混合标签。代码如下:
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
{
if arr != nil {
if section == 0 {
print("returning pending : \(pendingCount)")
return pendingCount
}
else{
print("returning scheduled count : \(scheduledCount)")
return scheduledCount
}
}
return 0
}
func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
if section == 0 {
return "Pending"
}
else{
return "Scheduled"
}
}
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 50.0
}
func numberOfSections(in tableView: UITableView) -> Int {
return 2
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
{
let data = arr![indexPath.row]
if indexPath.section == 0 {
if let cell = tableView.dequeueReusableCell(withIdentifier: "Pending") as? PendingTVC{
PendingTVC.formattCell(cell: cell, data: data)
cell.selectionStyle = .none;
cell.delegate = self
return cell
}
}
else{
if let cell = tableView.dequeueReusableCell(withIdentifier: "scheduledCell") as? ScheduledCell{
print("cellforrowat in scheduledCell")
ScheduledCell.formatCell(cell: cell, data: data)
cell.selectionStyle = .none;
return cell
}
}
return UITableViewCell()
}
请附上截图,以便更好地理解您的问题。 – Surjeet
你应该返回理想的单元格对象而不是UITableViewCell() – Ellen
@ air6199这没有任何效果。我将我的数据源分成两个数组,而不是 – user2363025