为导航控制器创建自定义类(即时崩溃) [英] Create custom class for Navigation Controller (Immediate crash)
问题描述
首先,我是一个新手,所以请在这里露出。
我在一个故事板的应用程序,构成多视图控制器通过 Navigation Controller (初始视图控制器)链接。这用作主屏幕。 我正在使用静态单元格和静态表格视图
我的新的,自定义类现在挂钩到我的故事板视图控制器。然后我输入(我相信是)正确的 numberOfSectionsInTableView :1和 numberOfRowsInSection :5(我有1节包括5行)。运行时,它会立即崩溃,并显示以下错误:
由于未捕获异常而终止应用程序 NSInternalInconsistencyException
',原因:'无法使具有标识符的单元出列队列 - 必须为标识符注册一个nib或一个类,或在故事板中连接一个原型单元
如果返回0部分和0行,一切正常(期望没有行显示)。 一旦我在其中任何一个中返回任何值> 0,就会发生此错误。
我错过了什么?还有什么其他我应该添加到文件,在它可以作为一个自定义类之前,我可以使用它作为任何其他自定义类吗?再次,我已经设置了界面生成器(storyboard)中的一切,包括表格单元格行,其样式等。我做错了什么?
编辑
我的表格视图设置
我的表格单元格设置
解决方案
- 将Cell添加为所有表格单元格的标识符
- 删除了表视图数据源方法。
感谢danh和rdelmar!
确保这是答案:在storyboard中,确保一个原型单元格被绘制在表视图(崩溃视图控制器中的一个),并确保它的重用标识符设置为单元格。您的代码为rowAtIndexPath:正在尝试将具有该标识符的单元格出队,但它不在那里。
标识符可以使用属性检查器右)在故事板。
First of all, I'm a newbie so please bare with me here.. 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?
Edit
My Table View Setup
My Table Cell Setup
Solution
- Adding "Cell" as the identifier to all table cell
- Removed the table view data source methods.
Thanks to danh and rdelmar!
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.
这篇关于为导航控制器创建自定义类(即时崩溃)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!