iOS/swift : two rows with same dequeue nib and identifier

标签 ios swift

我有一个包含多个部分的 TableView ,两个部分几乎相同,但它们的标题名称不同。所以我有一个注册的 Nib ,我在两行中使用它:

self.tableView.register(UINib(nibName: "ImprestDetailInfoHeaderTableViewCell", bundle: nil), forCellReuseIdentifier: "PaymentsReceiptsDetailsHeader")

在我的表格 View cellforrowat 中,我有这个:

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
        }

如您所见,第二和第三部分的第一行具有相同的定义。当我点击这两行中的任何一行时,我需要它们显示它们的详细信息,并且我更改了标题上的图像图标,但这似乎有一个冲突的行为,所以当我点击第一行时,这会改变两者的图标和类似奇怪的事情。这个问题是否有可能是因为两个单元格使用相同的 Nib 标识符? 因为我检查了我的代表,我发现那里没有问题,我唯一能想到的是在这些情况下快速内存管理中的一些错误。

更新: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")

看来问题已经解决了!!! (不同cell不同id)

关于iOS/swift : two rows with same dequeue nib and identifier,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53515098/

相关文章:

iphone - 如何将推送通知集成到现有应用程序中?

swift - 在 UserDefaults 中保存对象数组

ios - 如何制作一个包含类型的数组?

macos - 在 Swift 中从 Applescript 获取返回值

ios - 如何从另一个处于 segue 中的 View Controller 实例化导航和选项卡 Controller (显示详细信息)?

ios - Core-plot 实时数据重绘图

iphone - 从仅窗口模板创建应用程序时我缺少什么?

ios - Swift 中类似于 Youtube ID 的短随机唯一字母数字键

iphone - Frenzapp如何获取其他应用程序的版本?

ios - 如何使用 Swift Codable 处理部分动态的 JSON?