0

I am creating a very simple app and I am getting this error when I try to dequeue my tableview cell.

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "AnimalCell", for: indexPath) as! AnimalTableViewCell

    let animal = animals[indexPath.row]
    let thisLocation = locations.randomElement()
    cell.fillInTheDetails(animal: animal, location: thisLocation!)

    return cell
  }

I am getting an error when I call this

 let cell = tableView.dequeueReusableCell(withIdentifier: "AnimalCell", for: indexPath) as! AnimalTableViewCell

The error message is as follows:

TableViewWithMap[27537:9935669] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<NSObject 0x600001224030> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key animalName.'
*** First throw call stack:
(
    0   CoreFoundation                      0x00007fff20422fba __exceptionPreprocess + 242
    1   libobjc.A.dylib                     0x00007fff20193ff5 objc_exception_throw + 48
    2   CoreFoundation                      0x00007fff20422c5b -[NSException init] + 0
    3   Foundation                          0x00007fff207af46c

I've already registered this TableViewcell in viewDidLoad function

 override func viewDidLoad() {
    super.viewDidLoad()
    tableView.register(UINib(nibName: "AnimalTableViewCell", bundle: nil), forCellReuseIdentifier: "AnimalCell")
Maverick447
  • 175
  • 1
  • 11

3 Answers3

1

You've deleted a UIElement in your XIB with Interface Builder that had an outlet in your view controller without disconnecting the IBOutlet itself. Break the link for the animalName IBOutlet in your VC.

flanker
  • 3,840
  • 1
  • 12
  • 20
  • The error is definitely about broken IBOutlet connection. You will need to provide more info - the core of the VC so we can see what's happening with the outlets, and any code you have in the custom AnimalTableviewCell class. – flanker Jul 21 '21 at 11:39
0

Make sure the outlet is connected to the xib file correctly.
And check the class name and identifier of the cell are matched correctly.

I looked for a link that experienced the same error as you.
It would be good to refer to the answer of the link.

kyeahen
  • 161
  • 8
0

I redid the entire xib file and it worked! Not sure what the exact problem was!

Maverick447
  • 175
  • 1
  • 11