Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

dequeue reusable cell always crashes

in this code i add the programatic VC:

@IBAction func addPerson(_ sender: UIBarButtonItem) {
        let controller = CNContactPickerViewController()
        controller.delegate = self
        navigationController?.present(controller, animated: true, completion: nil)
    }

here i use to go on another VC when i click on a contact (to show info into cells and then i want to make a checkbox for phones/emails to show back in my first VC)

func contactPicker(_ picker: CNContactPickerViewController, didSelect contact: CNContact) {
        let vc = EditContactViewController()
        self.navigationController?.pushViewController(vc, animated: true)

i created a class for the next cell and i set up identifier as cell in storyboard when i do this in tableView cellForRowAtIndexPath

let cell = tableView.dequeueReusableCell(withIdentifier: "cell") as? ConfigCell

return cell!

this gives me:

fatal error: unexpectedly found nil while unwrapping an Optional value

i also tried withIdentifier,forIndexPath and it says:

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'

i deleted reuse identifier and put it back again , cleaned the application, restart, everything.

Thank You for your time!

like image 314
Marian Iconaru Avatar asked Nov 11 '16 23:11

Marian Iconaru


2 Answers

There can be several reason for this:

  1. If you have your UITableViewCell in controller itself, then check the reuse identifier whether it is set to "cell"

  2. If you have a separate .xib for your UITableViewCell, then

    a) Register the .nib of cell with your table view in viewDidLoad() of your controller

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

    Register the .nib only when you are sure the outlet of table view is set. Otherwise, if the outlet if table view is still nil, it won't register the .nib of your cell.

    b) Check whether the reuse identifier is set to "cell"

like image 71
PGDev Avatar answered Sep 21 '22 23:09

PGDev


Make sure there is no '!' sign in interface outlet connections

enter image description here

like image 35
Sazzad Hissain Khan Avatar answered Sep 24 '22 23:09

Sazzad Hissain Khan