gpt4 book ai didi

ios - TableView Controller 中的第二个自定义单元格生成错误

转载 作者:行者123 更新时间:2023-11-30 13:57:50 26 4
gpt4 key购买 nike

我有一个 UITableViewController,其中使用多个自定义单元格。我过去使用过多个自定义单元格,没有任何问题,并且我使用与过去相同的策略来实现它们,所以这个错误让我感到困惑。首先,一些代码:

这是我在 viewDidLoad 中注册自定义单元格的方式:

    // Registering the custom cell
let nib1 = UINib(nibName: "OmniCell", bundle: nil)
tableView.registerNib(nib1, forCellReuseIdentifier: "omniCell")

let nib2 = UINib(nibName: "RankCell", bundle: nil)
tableView.registerNib(nib2, forCellReuseIdentifier: "rankCell")

这就是我在 cellForRowAtIndexPath 中创建它们的方法:

    let cell1: OmniCell = self.tableView.dequeueReusableCellWithIdentifier("omniCell") as! OmniCell
let cell2: RankCell = self.tableView.dequeueReusableCellWithIdentifier("rankCell") as! RankCell

当我注释掉与第二个自定义单元格相关的代码时,程序运行正常,但是当使用两个自定义单元格时,我收到此错误:

this class is not key value coding-compliant for the key rankCell.

两个自定义单元格都以相同的方式实现,因此我不确定为什么第二个自定义单元格会生成此错误,而第一个自定义单元格不会生成此错误。我错过了什么?

更新:根据要求,我正在共享整个 cellforrowatindexpath 函数:

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

// This line works:
let cell1: OmniCell = self.tableView.dequeueReusableCellWithIdentifier("omniCell") as! OmniCell

// It is this line that breaks if not commented out:
let cell2: RankCell = self.tableView.dequeueReusableCellWithIdentifier("rankCell") as! RankCell

// This line works:
let cell3: ProgressCell = self.tableView.dequeueReusableCellWithIdentifier("progressCell") as! ProgressCell


if indexPath.row == 0 {
return cell1
} else if indexPath.row == 1 {
return cell2
} else {
return cell3
}

}

最佳答案

我设法解决了这个问题。问题是 XIB 中存在错误连接。引用这张图:

enter image description here

在一个好的 socket 上方还有一个“损坏”的 socket ,如下所示: RankCell ---> Rank Cell但它不是一个实心圆圈,而是一个看起来细长的符号,因为太小而无法辨认。我移除了 socket ,应用程序正常构建并运行。我不确定该连接从何而来,其他自定义单元格都没有类似的连接。

关于ios - TableView Controller 中的第二个自定义单元格生成错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33383913/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com