【问题标题】:What action when tableview can't dequeue a cell当tableview无法出列单元格时采取什么措施
【发布时间】:2021-10-06 16:42:40
【问题描述】:

当我学习 tableviews 时,我遵循的教程使用了以下代码-

guard let cell = tableView.dequeueReusableCell(withIdentifier: Self.reminderListCellIdentifier, for: indexPath) as? ReminderListCell else {
        return UITableViewCell()
    }

我刚刚遇到了来自 Apple 的示例代码;

guard let cell = tableView.dequeueReusableCell(withIdentifier: Self.reminderListCellIdentifier, for: indexPath) as? ReminderListCell else {
        fatalError("Unable to dequeue ReminderCell")
    }

我应该实现什么?我相信 fatalError 会导致崩溃。是期望的行为吗?

【问题讨论】:

    标签: ios uitableview


    【解决方案1】:

    没有任何建议。强制解开单元格

    let cell = tableView.dequeueReusableCell(withIdentifier: Self.reminderListCellIdentifier, for: indexPath) as! ReminderListCell
    

    实际上,它会导致与fatalError 相同的行为。 如果一切都正确连接,则代码不得崩溃。潜在的错误是设计错误。

    第一个 sn-p 非常愚蠢,因为在提到的设计错误的情况下,什么都不会显示,你也不知道为什么。

    强制展开本身并不邪恶。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-02-21
      • 1970-01-01
      • 2012-04-26
      • 1970-01-01
      • 2018-11-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多