简体   繁体   English

班级插座的实例未分配

[英]Instance of class's outlets are unallocated

I have a subclass of UITableCell called HistoriqueCell . 我有一个名为HistoriqueCellUITableCell子类。 This class has outlets (4 labels). 此类有插座(4个标签)。 I have a UIViewController ( HistoriqueViewController ) that has a UITableView . 我有一个具有UITableViewUIViewControllerHistoriqueViewController )。 This table has a prototype cell subclassed with HistoriqueCell . 该表具有一个以HistoriqueCell子类化的原型单元。 That prototype cell's four labels are linked to the outlets of HistoriqueCell.h . 该原型单元的四个标签链接到HistoriqueCell.h的出口。 However all my instance of those cell always have unallocated outlets. 但是,我所有这些单元的实例始终都有未分配的出口。 My colleague's version is working perfectly and it's the exact same code (we bypassed git and I simply loaded his copied project from his usb stick just to be 100% sure it wasn't git, even though git assured us there already was no difference). 我的同事的版本运行正常,并且代码完全相同(我们绕过了git,我只是从他的usb棒中加载了他复制的项目,只是为了100%确保它不是git,即使git保证我们已经没有区别了) 。

This makes me suspect that the problem doesn't lie in the code but in a xcode config. 这使我怀疑问题不在于代码,而在于xcode配置。 I remember I had a similar problem way back that was due to localized storyboard . 我记得我曾经有过类似的问题,这是由于本地情节提要所致。 Simply put, the french version was loaded and had no outlets connected in it, contrary to the english version where I put the outlets. 简而言之,法语版本已加载,并且没有连接插座,这与我放置插座的英语版本相反。 When the french storyboard was used the outlets were unallocated like the problem I have now, but my storyboard is not localized. 使用法语情节提要时,像我现在遇到的问题一样,未分配出口,但情节提要板未本地化。

Here's the debug showing my unallocated outlets 这是显示我未分配的出口的调试

Here's the storyboard, I also have the @synthesize in the .m 这是情节提要,我在.m中也有@synthesize

Example of cell usage : 电池使用示例:

My really really frustrated on the problem, I can't seem the find the issue. 我真的对这个问题感到沮丧,我似乎找不到问题。 Please, if anyone have any leads I'm all ears! 拜托,如果任何人有任何线索,我都听不见!

This is expected as nib file isn't loaded automatically. 这是预期的,因为笔尖文件不会自动加载。

You should either load the nib file manually by calling [[NSBundle mainBundle] loadNibNamed:@"HistoriqueCell" owner:self options:nil] . 您应该通过调用[[NSBundle mainBundle] loadNibNamed:@"HistoriqueCell" owner:self options:nil]手动加载nib文件。

Or preferably register the nib object with the table view as following: 或者最好在表视图中注册笔尖对象,如下所示:

UINib *cellNib = [UINib nibWithNibName:@"HistoriqueCell" bundle:nil];
[self.tableView registerNib:cellNib forCellReuseIdentifier:@"HistoriqueCell"];

And now, when you call dequeueReusableCellWithIdentifier: the table view will either return a reusable cell, or create a new instance of the cell and load the nib for you. 现在,当您调用dequeueReusableCellWithIdentifier:表视图将返回可重用的单元格,或创建该单元格的新实例并为您加载笔尖。 And this check won't be needed anymore: 并且不再需要此检查:

if (cell == nil) {
    ...
}

也许您在代码中将“单元格”设置为类似于标识ID,但在Interface Builder中未设置单元格

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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