Tander Tander - 3 months ago 27
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

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
it is only called twice for the first table view:

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
it is working for

Can anyone tell me where I am going wrong here?


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