当 tableview 无法使单元格出列时采取什么操作

What action when tableview can't dequeue a cell

当我学习表格视图时,我所遵循的教程使用了以下代码-

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 会导致崩溃。是期望的行为吗?

None 个建议。强制打开单元格

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

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

第一个片段非常愚蠢,因为如果出现上述设计错误,则不会显示任何内容,您也不知道为什么。

强制展开本身并不是邪恶的。