简体   繁体   中英

Instance of class's outlets are unallocated

I have a subclass of UITableCell called HistoriqueCell . This class has outlets (4 labels). I have a UIViewController ( HistoriqueViewController ) that has a UITableView . This table has a prototype cell subclassed with HistoriqueCell . That prototype cell's four labels are linked to the outlets of 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).

This makes me suspect that the problem doesn't lie in the code but in a xcode config. 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

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] .

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. And this check won't be needed anymore:

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

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

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