Create custom class for Navigation Controller (Immediate crash)

丶灬走出姿态 提交于 2020-01-16 19:08:14

问题


I'm working on a Storyboards based app which constitutes of multiple view controllers linked via a Navigation Controller (initial view controller). This is used as the home screen. I'm using static cells and a static table view.

Now, I want to hook up some labels, buttons, etc as outlets/actions to "the .h" file and subsequently write custom methods in the .m file. But (as expected?) there's yet no custom class to select from in the identity inspector. So I created a new custom class as a subclass of UITableViewController (which seems to be the correct one?)

My new, custom class is now hooked up to my storyboard view controller. I then enter (what I believe to be) the correct numberOfSectionsInTableView: 1, and numberOfRowsInSection:5 (I got 1 section including 5 rows). When ran, it immediately crashes with the following error:

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'unable to dequeue a cell with identifier Cell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'

If return 0 sections and 0 rows, everything works fine (expect there are no rows displayed). Once I return anything > 0 in either of them, it crashes with this error.

What have I missed? Is there anything else I'm supposed to add to the file before it can be attached as a custom class and I can use it as any other custom class? Again, I've set up everything in the interface builder (storyboard), including the table cell rows, its styling, etc. What am I doing wrong?

My Table View Setup

My Table Cell Setup


回答1:


Pretty sure this is the answer: in storyboard, make sure a prototype cell is painted on the table view (the one in the crashing view controller) and make sure it has a reuse identifier set to "Cell". Your code for rowAtIndexPath: is trying to dequeue a cell with that identifier and it's not there.

The identifier can be set using the attributes inspector (the middle tab on the upper right) in storyboard.



来源:https://stackoverflow.com/questions/14792772/create-custom-class-for-navigation-controller-immediate-crash

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!