UITableViewCell outlets not set during bundle load (possibly very elementary question)
Posted
by Jan Zich
on Stack Overflow
See other posts from Stack Overflow
or by Jan Zich
Published on 2010-05-22T15:39:34Z
Indexed on
2010/05/22
16:00 UTC
Read the original article
Hit count: 309
What are the most common reasons for an outlet (a class property) not being set during a bundle load?
I'm sorry; most likely I'm not using the correct terms. It's my first steps with iPhone OS development and Objective-C, so please bear with me. Here is more details. Basically, I'm trying to create a table view based form with a fixed number of static rows. I followed this example:
Scroll down to The Technique for Static Row Content please. I have one nib file with one table view, three table cells and all connections set as in the example. The problem is that the corresponding cell properties in my controller are never initialised. I get an exception in cellForRowAtIndexPath complaining that the returned cell is nil: UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath
.
Here are the relevant parts from the implementation of the controller:
@synthesize cellA;
@synthesize cellB;
@synthesize cellC;
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView
numberOfRowsInSection:(NSInteger)section
{
return 3;
}
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
switch (indexPath.row)
{
case 0: return cellA; break;
case 1: return cellB; break;
case 2: return cellC; break;
default: return nil;
}
}
And here is the interface part:
@interface AssociatePhoneViewController : UITableViewController
{
UITableViewCell *cellA;
UITableViewCell *cellB;
UITableViewCell *cellB;
}
@property (nonatomic, retain) IBOutlet UITableViewCell *cellA;
@property (nonatomic, retain) IBOutlet UITableViewCell *cellB;
@property (nonatomic, retain) IBOutlet UITableViewCell *cellC;
@end
This must be possibly one of the the most embarrassing questions on StackOverflow. It looks like the most basic example code.
Is is possible that the cells are not instantiated with the nib file? I have them on the same level before the tabula view in the nib file. I tried to move them after the table view, but it did not make any difference.
Are table cells in some way special? Do I need to set some flag or some property on them in the nib file? I was under the impression that all classes (views, windows, controllers …) listed in a nib file are simply instantiated (and linked using the provided connections).
Could it possibly be some memory issue? The cell properties in my controller are not defined in any special way.
© Stack Overflow or respective owner