gpt4 book ai didi

swift - 出列可重复使用的单元格总是崩溃

转载 作者:搜寻专家 更新时间:2023-10-30 22:29:29 24 4
gpt4 key购买 nike

在此代码中,我添加了程序化 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'

我删除了重用标识符并将其重新放回去,清理了应用程序,重新启动,一切。

感谢您的宝贵时间!

最佳答案

这可能有几个原因:

  1. 如果您的 UITableViewCell 位于 Controller 本身,请检查重用标识符 是否设置为 "cell"

  2. 如果您的UITableViewCell 有单独的.xib,那么

    a) 在 Controller 的 viewDidLoad() 中用表格 View 注册单元格的 .nib

    self.tableView.register(UINib(nibName:"CustomTableViewCell"), forCellWithReuseIdentifier: "cell")

    仅当您确定table viewoutlet 已设置时才注册.nib。否则,如果 outlet if table view 仍然是 nil,它不会注册你的 .nib单元格。

    b) 检查重用标识符是否设置为"cell"

关于swift - 出列可重复使用的单元格总是崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40557899/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com