Why does IBOutletCollection point to static cells from a storyboard that returns zero?

I defined this in code:

@property (nonatomic, weak) IBOutletCollection(UITableViewCell) NSSet * certaintyCells; 

and is synthesized. I am absolutely sure that this controller is used in the bulletin board and has connected three cells to this collection.

Next, in the call to the didSelectRowAtIndexPath: method, I added this code by adding an NSLog for debugging:

  NSLog(@"Certainty Cells: %@",certaintyCells); for (UITableViewCell * cell in certaintyCells) { [cell.textLabel setTextColor:[UIColor colorWithRed:0 green:0 blue:0 alpha:1]]; [cell setSelectionStyle:UITableViewCellSelectionStyleBlue]; } 

Output:

 Certainty Cells: (null) 

And, of course, the expected behavior does not occur.

Any ideas as to why this is happening? I am sure that I am using static cells, not dynamic prototypes. As an additional note, these three cells are also associated with (working) individual IBOutlets.

Thanks,

+8
iphone storyboard iboutlet
source share
2 answers

I found the answer, making changes that at that time did not make sense. I changed the property from weak to strong and it worked.

Why did I have (weak) in the first place:

Because I didnโ€™t want something to be released if the view decided to unload due to memory warnings, etc.

Why is this wrong thinking:

Because IBOutletCollection is an instance of NSSet or NSArray. that NSSet / NSArray is not saved in the view because it is not a subview itself. With IBOutlet a weak property is fine, with IBOutletCollection a strong property is required, otherwise the reference count is immediately zero and freed.

I leave it here in the hope that it will help someone else.

+33
source share

I would say that the (null) value is a consequence of the release of the object, since ARC guessed that the object does not refer to anyone and sets the value to nil, and then releases it at some point.

+3
source share

All Articles