为导航控制器创建自定义类(即时崩溃) [英] Create custom class for Navigation Controller (Immediate crash)

查看:276
本文介绍了为导航控制器创建自定义类(即时崩溃)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我是一个新手,所以请在这里露出。
我在一个故事板的应用程序,构成多视图控制器通过 Navigation Controller (初始视图控制器)链接。这用作主屏幕。 我正在使用静态单元格和静态表格视图

现在,我想将一些标签,按钮等连接为插座/动作以 .h 文件,随后在.m文件中编写自定义方法。但是(如预期?)身份检查器中没有要选择的自定义类。所以我创建了一个新的自定义类作为 UITableViewController 这似乎是正确的)的子类



我的新的,自定义类现在挂钩到我的故事板视图控制器。然后我输入(我相信是)正确的 numberOfSectionsInTableView :1和 numberOfRowsInSection :5(我有1节包括5行)。运行时,它会立即崩溃,并显示以下错误:



由于未捕获异常而终止应用程序 NSInternalInconsistencyException ',原因:'无法使具有标识符的单元出列队列 - 必须为标识符注册一个nib或一个类,或在故事板中连接一个原型单元



如果返回0部分和0行,一切正常(期望没有行显示)。 一旦我在其中任何一个中返回任何值> 0,就会发生此错误。



我错过了什么?还有什么其他我应该添加到文件,在它可以作为一个自定义类之前,我可以使用它作为任何其他自定义类吗?再次,我已经设置了界面生成器(storyboard)中的一切,包括表格单元格行,其样式等。我做错了什么?



编辑



我的表格视图设置





我的表格单元格设置





解决方案




  1. 将Cell添加为所有表格单元格的标识符

  2. 删除了表视图数据源方法。

感谢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

  1. Adding "Cell" as the identifier to all table cell
  2. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆