在此代码中,我添加了程序化 VC:
@IBAction func addPerson(_ sender: UIBarButtonItem) {
let controller = CNContactPickerViewController()
controller.delegate = self
navigationController?.present(controller, animated: true, completion: nil)
}
在这里,当我点击一个联系人时,我会转到另一个 VC(将信息显示到单元格中,然后我想为电话/电子邮件制作一个复选框以在我的第一个 VC 中显示)
func contactPicker(_ picker: CNContactPickerViewController, didSelect contact: CNContact) {
let vc = EditContactViewController()
self.navigationController?.pushViewController(vc, animated: true)
我为下一个单元格创建了一个类,并将标识符设置为 Storyboard中的单元格 当我在 tableView cellForRowAtIndexPath 中执行此操作时
let cell = tableView.dequeueReusableCell(withIdentifier: "cell") as? ConfigCell
return cell!
这给了我:
fatal error: unexpectedly found nil while unwrapping an Optional value
我也试过 withIdentifier,forIndexPath 并且它说:
2016-11-12 01:35:28.626 iEvents3[2637:47714] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'unable to dequeue a cell with identifier cell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'
我删除了重用标识符并将其重新放回去,清理了应用程序,重新启动,一切。
感谢您的宝贵时间!
最佳答案
这可能有几个原因:
如果您的
UITableViewCell
位于 Controller 本身,请检查重用标识符 是否设置为"cell"
如果您的
UITableViewCell
有单独的.xib
,那么a) 在 Controller 的
viewDidLoad()
中用表格 View 注册单元格的 .nibself.tableView.register(UINib(nibName:"CustomTableViewCell"), forCellWithReuseIdentifier: "cell")
仅当您确定
table view
的outlet
已设置时才注册.nib
。否则,如果outlet
iftable view
仍然是nil
,它不会注册你的.nib
单元格。b) 检查重用标识符是否设置为
"cell"
关于swift - 出列可重复使用的单元格总是崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40557899/