简体   繁体   中英

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?

您使用的是错误的注册方法,正在注册应使用registerNib:forHeaderFooterViewReuseIdentifier:的单元格registerNib:forHeaderFooterViewReuseIdentifier:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM