Tander Tander - 1 month ago 7
Objective-C Question

When I have 2 tableviews in one view controller, cellForRowAtIndexPath doesn't get called for second UITableView

I have a UIView that gets loaded from a xib file. It has two UITableView's. I wanted to display different data in each UITableView and decided not to use indexPath.section.

So with that in mind - I wrote up my

cellForRowAtIndexPath
like this:

-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *UsernameCellIdentifier = @"UsernameCell";
static NSString *PasswordCellIdentifier = @"PasswordCell";
static NSString *mailListTableViewCellIdentifier = @"Cell";
if (tableView == self.maillistTableview ){

UITableViewCell *cell = [self.maillistTableview dequeueReusableCellWithIdentifier:mailListTableViewCellIdentifier];
if (!cell){

cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:mailListTableViewCellIdentifier];
}


cell.textLabel.text = @"Cells";
return cell;
}


if (tableView == self.tableView){

if(indexPath.row == 0) {

self.usernameCell = (BBUsernameTableViewCell *)[tableView dequeueReusableCellWithIdentifier:UsernameCellIdentifier];

if(!self.usernameCell) {

NSArray *nib = [[NSBundle mainBundle] loadNibNamed:UsernameCellIdentifier owner:self options:nil];

return self.usernameCell;
}

return nil;
}


When I set a breakpoint on
cellForRowAtIndexPath
it is only called twice for the first table view:
self.tableView


I added an NSLog inside of cellForRowAtIndexPath to see which tableView it was looking at and it never "checks" self.maillistTableView

I have connected the delegates for that UITableView to the file owner.

Interestingly in
numberOfRowsInSection
it is working for
self.maillistTableView
.

Can anyone tell me where I am going wrong here?

Answer

Since numberOfRowsInSection is working, check it's return count. If the datasource array count is zero, then cellForRowAtIndexPath will not work.