My question is very similar to this one.
My custom prototype cells designed in Interface Builder using storyboards have all the internal objects set to nil (not created), so when I try to assign values to them, they remain blank.
I am using Xcode 4.6.2, and running the code in the 6.1 iPhone simulator. Here is what I've done:
At the moment, the table displays with the correct number of sections & rows, but the values of the cell are not being set.
This is the cellForRowAtIndexPath:(NSIndexPath *)indexPath
code:
NewServerCell *cell = [tableView dequeueReusableCellWithIdentifier:@"serverNameCell"];
I always get back a cell, and the memory location seems to be ok for a valid object.
But when I try to cell.name.text = [thisServer name];
I find that the cell.name
label is always nil.
There are no crashes - but my fields are not being set.
I have checked a million times that the identifier is ok - it is! I have gone through the Apple documentation for custom cells from a storyboard - but still get this frustrating issue..
Anyone else had this, and resolved it?
I had this exact problem today with Xcode 5's storyboard. After pulling almost all my remaining hair out, I noticed I was calling this in viewDidLoad
:
[self.tableView registerClass:[SwitchTableViewCell class] forCellReuseIdentifier:@"Setting"];
Whoops! This line is unnecessary when using prototype cells in storyboards. The storyboard automatically configures this for me. SwitchTableViewCell *tableViewCell = [tableView dequeueReusableCellWithIdentifier:@"Setting" forIndexPath:indexPath];
works just fine without calling registerClass::
explicitly.
The question still remains of why calling registerClass::
causes some outlets to not be connected.
An easy workaround for this problem is to tag the UILabel in the prototype and manipulate it with:
UILabel* label = [cell viewWithTag:cellTag];
label.text = [thisServer name]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With