我对牢房内部有疑问。 如果我找不到dequeueusablecell,那么如果特定类型的单元格没有dequed,我应该显式地崩溃应用程序。
示例-:
guard let productImageSideViewsCell = tableView.dequeueReusableCell(withIdentifier: ProductsSideViewsCell.identifier, for: indexPath) as? ProductsSideViewsCell else { fatalError("productImageSideViewsCell not found at indexpath \(indexPath)") }
这样做最好还是有其他方法
最好的方法是强制解开排队的牢房(不是开玩笑)。
let productImageSideViewsCell = tableView.dequeueReusableCell(withIdentifier: ProductsSideViewsCell.identifier, for: indexPath) as! ProductsSideViewsCell
首先是API dequeueReusableCell(withIdentifier:for:) 始终返回有效的单元格。
dequeueReusableCell(withIdentifier:for:)
这是一种罕见的情况,强制拆解非常有用,因为它发现 设计 错误。 如果在运行时不会改变代码的接口生成器中所有内容都连接正确 不能 撞车。