Reputation: 846
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.
Upvotes: 1
Views: 872
Reputation: 886
If you do not do anything with your IBOutlet why do you have it? The method
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
is Called by the nib-File for the tableView instance created in the nib.Your Class as a delegate of this instance receives this call. Being the delegate of the tableView in the nib is all you need.
Upvotes: 0
Reputation: 9935
I'm almost sure that this error occurs because you have improperly connected your UITableView
. You should delete an ivar mTableView, an IB
outlet property tableView and @synthesize
. Then DELETE AN OUTLET IN IB
. 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)
Upvotes: 1
Reputation: 4092
Make sure that you have set the delegate and the datasource of the table within Interface Builder
Upvotes: 0