ios - 奇怪的 UITableView 错误 : "Assertion Failure" on dequeuing static cells in storyboard

标签 ios iphone xcode swift uitableview

我收到此错误:*** 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中的单元格。它们被设置为静态的,并且在检查器中设置了正确的类(尽管它获得了正确的值这一事实应该很清楚)

enter image description here

如有任何想法或帮助,我们将不胜感激。我正在使用 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/

相关文章:

ios - 如何应用复杂的 CALayer 变换更改?

ios - 如何导航回上一个 View

iphone - 通用二进制文件不是对设备内存的巨大浪费吗?

iphone - 无法通过 UINavigationcontroller.viewControllers 更改类的属性

iphone - 未选择 Controller 的 UITabBarController

ios - 如何为 tableview 的最后一个可见单元格创建不同的 View

ios - 更新使用 iBooks Author 创建的图书

xcode - 我怎样才能摆脱错误消息 "Ambiguous use of internal linkage declaration ' .. .' defined in multiple modules"

ios - Touch Event 在旋转时点击 UIImageView

Swift 框架 "Module ' 找不到 RealityKit”