我有一个表视图,它有几个部分,两个部分几乎相同,但它们的头名称不同。所以我有一个注册的笔尖,我分两行使用:
self.tableView.register(UINib(nibName: "ImprestDetailInfoHeaderTableViewCell", bundle: nil), forCellReuseIdentifier: "PaymentsReceiptsDetailsHeader")
在我的单元格中,我看到了这个:
case 2:
if indexPath.row == 0 {
let cell = tableView.dequeueReusableCell(withIdentifier: "PaymentsReceiptsDetailsHeader", for: indexPath) as! ImprestDetailInfoHeaderTableViewCell
cell.selectionStyle = .none
cell.headerType = ImprestDetailInfoType.payment
cell.checkedAndTotalNumber = self.imprestViewModel.getStringCheckedAndTotalNumberOfPayments()
self.paymentHeaderDelegate = cell
return cell
} else {
let cell = tableView.dequeueReusableCell(withIdentifier: "AddImprestPaymentsReceiptsDetailTableView", for: indexPath) as! ImprestReceiptPaymentDetailTableViewCell
cell.imprestItems = self.imprestViewModel.getPaymentsImprestItems()
cell.delegate = self.imprestViewModel
return cell
}
case 3:
if indexPath.row == 0 {
let cell = tableView.dequeueReusableCell(withIdentifier: "PaymentsReceiptsDetailsHeader", for: indexPath) as! ImprestDetailInfoHeaderTableViewCell
cell.selectionStyle = .none
cell.headerType = ImprestDetailInfoType.receipt
cell.checkedAndTotalNumber = self.imprestViewModel.getStringCheckedAndTotalNumberOfReceipts()
self.receiptHeaderDelegate = cell
return cell
} else {
let cell = tableView.dequeueReusableCell(withIdentifier: "AddImprestPaymentsReceiptsDetailTableView", for: indexPath) as! ImprestReceiptPaymentDetailTableViewCell
cell.imprestItems = self.imprestViewModel.getReceiptsImprestItems()
cell.delegate = self.imprestViewModel
return cell
}
正如您所看到的,第二节和第三节的第一行具有相同的定义。当我点击这两行中的任何一行时,我需要它们显示它们的详细信息,并更改标题上的图像图标,但这似乎有冲突行为,所以当我点击第一行时,这会更改两者的图标以及类似的奇怪事物。这个问题有可能是因为两个细胞使用相同的笔尖标识符吗?cus我检查了我的代表,发现没有问题,我唯一能想到的是针对这些情况的快速内存管理中的一些错误。
UPD:didSelectRowAtIndexPath:
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if indexPath.section == 1 {
self.delegate?.summartySectionDidTapped()
} else if indexPath.section == 2 && indexPath.row == 0 {
self.paymentsDetailIsOn.toggle()
self.paymentHeaderDelegate?.detailHeaderSelected()
} else if indexPath.section == 3 && indexPath.row == 0 {
self.receiptsDetailIsOn.toggle()
self.receiptHeaderDelegate?.detailHeaderSelected()
}
}
我更改了
self.tableView.register(UINib(nibName: "ImprestDetailInfoHeaderTableViewCell", bundle: nil), forCellReuseIdentifier: "PaymentsReceiptsDetailsHeader")
至
self.tableView.register(UINib(nibName: "ImprestDetailInfoHeaderTableViewCell", bundle: nil), forCellReuseIdentifier: "PaymentsDetailsHeader")
self.tableView.register(UINib(nibName: "ImprestDetailInfoHeaderTableViewCell", bundle: nil), forCellReuseIdentifier: "ReceiptsDetailsHeader")
看来问题解决了!!!(不同细胞的不同id(
如果要在节中插入标头,可以使用函数func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView?
根据的需要实现tableView更简单