I'm new to Swift, and am trying to connect a custom UITableViewHeaderFooterView with a nib to my viewcontroller. When I do, I get this common error, which I've dealt with before and which is summarized in this post.
However this time, I'm a bit confused as to what optional is being unwrapped and hence how to fix the problem.
As far as I can tell everything is hooked up correctly-- the UITableView I'm using (menuTableView) is connect to the IBOutlet, as are all the parts of the custom header in the nib. The identifier and nib name are correct as well. Any idea what's going on? Here's the code where the error is originating:
menuTableView.register(UINib(nibName: "MenuTableHeader", bundle: nil), forHeaderFooterViewReuseIdentifier: "MenuTableHeader")
And here's my MenuTableHeader.swift file, minus a function or two.
class MenuTableHeader: UITableViewHeaderFooterView {
@IBOutlet var menuTableHeader: UIView!
@IBOutlet var menuHeaderLabel: UILabel?
@IBOutlet var menuHeaderImage: UIImageView?
var delegate: MenuTableHeaderDelegate?
var section: Int = 0
override init(reuseIdentifier: String?) {
super.init(reuseIdentifier: reuseIdentifier)
// Call tapHeader when tapping on this header
addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(MenuTableHeader.tapHeader(_:))))
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
Thanks!