guard let cell = tableView.dequeueReusableCell(withIdentifier: Self.reminderListCellIdentifier, for: indexPath) as? ReminderListCell else {
return UITableViewCell()
}
我剛剛看到了蘋果公司的示例代碼,它是;
guard let cell = tableView.dequeueReusableCell(withIdentifier: Self.reminderListCellIdentifier, for: indexPath) as? ReminderListCell else {
fatalError("Unable to dequeue ReminderCell"/span>)
}
我應該如何實作?fatalError會導致崩潰,我相信。這是我想要的行為嗎?
uj5u.com熱心網友回復:
沒有任何建議。強制解包單元格
let cell = tableView.dequeueReusableCell(withIdentifier: Self.reminderListCellIdentifier, for: indexPath) as! ReminderListCell
在實踐中,它引起的行為與fatalError相同。
如果所有的東西都被正確地連接起來,代碼一定不會崩潰。潛在的錯誤是一個設計錯誤。
第一個片段非常愚蠢,因為如果出現上述設計錯誤,將不會顯示任何東西,而且你也不知道為什么。
強制解包本身并不邪惡。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/311753.html
標籤:
