I'm trying to make a custom headerView for my tableview. I have followed many guides but can't resolve one problem.
- I used to subclass UITableViewHeaderFooterView and created xib file.
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.