tableview 无法使单元格出列时的操作

时间:2021-07-31 13:56:46

标签: ios uitableview

当我学习 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")
    }

我应该实施什么?我相信致命错误会导致崩溃。是想要的行为吗?

1 个答案:

答案 0 :(得分:1)

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

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

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

第一个片段非常愚蠢,因为在提到的设计错误的情况下,不会显示任何内容,您也不知道为什么。

强制展开本身并不邪恶。

相关问题