Liam Shalon
Liam Shalon

Reputation: 442

Header Custom View: unexpectedly found nil while unwrapping an Optional value

I'm getting an error when I run my code. The error is all in the line below within the viewForHeaderInSection function.

let header:friendsListSectionHeader = self.friendsTableView.dequeueReusableHeaderFooterViewWithIdentifier("friendsSection") as! friendsListSectionHeader

and I reference it like this in the viewDidLoad.

let nib2 = UINib(nibName: "friendsListSectionHeader", bundle: nil)
        friendsTableView.registerNib(nib2, forCellReuseIdentifier: "friendsSection")

I do have a custom view for a cell above this if that does anything. Everything builds, but I get an error that I'm unexpectedly found nil while unwrapping an Option value.

My .xib and UITableViewHeaderFooterView class are all referenced correctly.

Any thoughts?

Upvotes: 1

Views: 627

Answers (1)

Wain
Wain

Reputation: 119031

You're just using the wrong registration method, you're registering a cell where you should be using registerNib:forHeaderFooterViewReuseIdentifier:

Upvotes: 2

Related Questions