I have this problem I’ve been sitting with. My tableView that I put inside my UIView is not populating or sometimes I get an exception.
// .h
@interface List : UIViewController <UITableViewDelegate, UITableViewDataSource>
{
UITableView *mTableView;
}
@property (nonatomic, readonly) IBOutlet UITableView *tableView;
//------------------------------
// .m
@synthesize tableView=mTableView;
//Further I do the normal viewDidUnload stuff = nill
//And the numberOfSectionsInTableView, numberOfRowsInSection and
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"cellForRowAtIndexPath:");
NSLog(@"Table View: %@",[tableView description]);
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.textLabel.text = @"Hi";
// Configure the cell...
return cell;
}
I get as output:
*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<List 0x6a78000> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key tableView.'
or just a list of empty cells, not even “Hi” as a title.
I’m almost sure that this error occurs because you have improperly connected your
UITableView. You should delete an ivar mTableView, anIBoutlet property tableView and@synthesize. Then DELETE AN OUTLET INIB. Then, connect it again by dragging it from the interface builder and DO NOT TYPE ANY CODE in your class. Xcode will do all stuff for you (create a property, synthesize it and do MM things)