0

I'm trying to make a custom headerView for my tableview. I have followed many guides but can't resolve one problem.

  1. I used to subclass UITableViewHeaderFooterView and created xib file.

enter image description here

Added view (to be a container view) into xib file. First problem - when I`m trying to change class to CustomHeaderViewClass Xcode doesn't autocomplete it. I don't know why Xcode can't see this class.

Then, inside ViewController I register headerview:

let nib = UINib(nibName: "CustomHeaderView", bundle: nil)
tableView.register(nib, forHeaderFooterViewReuseIdentifier: "HeaderIdentifier")

And calling method:

func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
    let cell = tableView.dequeueReusableHeaderFooterView(withIdentifier: "HeaderIdentifier") as! CustomHeaderViewClass
    cell.textLabel?.text = "Section: \(section)"
    return cell
}

And then my app always crashes with Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<NSObject 0x600001314c10> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key centerLabel.'

centerLabel is name of label inside xib file.

Max
  • 43
  • 2
  • 8
  • Click on connections-inspector and check if the outlet is connected. – RTXGamer Sep 15 '21 at 14:47
  • @RTXGamer everything is connected. I also tried to set object as file`s owner and as custom header view class but result is the same ;( – Max Sep 15 '21 at 16:17
  • Does this answer your question? [Load XIB this class is not key value coding-compliant for the key](https://stackoverflow.com/questions/51056322/load-xib-this-class-is-not-key-value-coding-compliant-for-the-key) – RTXGamer Sep 15 '21 at 17:04

0 Answers0