我收到此错误:*** Assertion failure in -[UITableView dequeueReusableCellWithIdentifier:forIndexPath:] with static cells.
我的代码在 Swift 中(重用标识符是在文件中设置为常量的字符串):
...
private let topTableViewCellIdentifier = "topTableViewCell"
private let bottomTableViewCellIdentifier = "bottomTableViewCell"
...
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let reuseIdentifier = (indexPath.section == 0) ? topTableViewCellIdentifier : bottomTableViewCellIdentifier
let cell = tableView.dequeueReusableCellWithIdentifier(reuseIdentifier, forIndexPath: indexPath)
return cell
}
我在堆栈溢出中搜索了这个错误,并找到了一堆答案,基本上都在说同样的事情:确保重用标识符与 Storyboard 中单元格的重用标识符相同。
然而,就我而言,它是。
我已反复确认这一点,并反复从一个剪切粘贴到另一个以确保情况确实如此。 Xcode 清楚地表明正在设置正确的值。我打扫过了。我什至重新启动。我已经做了我能想到的一切,它没有看到 Storyboard中的单元格。它们被设置为静态的,并且在检查器中设置了正确的类(尽管它获得了正确的值这一事实应该很清楚)
如有任何想法或帮助,我们将不胜感激。我正在使用 El Capitan 和 Xcode 7。
最佳答案
如果您尝试为 TableView 使用静态布局,您通常不会实现 tableView:cellForRowAtIndexPath:
,UITableViewController
会为您完成此操作。为静态配置的 UITableView
调用 dequeueReusableCellWithIdentifier:forIndexPath:
方法无效(如错误所示)。
关于ios - 奇怪的 UITableView 错误 : "Assertion Failure" on dequeuing static cells in storyboard,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32916243/