cellForRowAtIndexPath not called for all sections
- by Wynn
I have a UITableView that has five sections. Just as the title describes cellForRowAtIndexPath is only being called for the first four. All connections have been made concerning the datasource and delegate. Also, my numberOfSectionsInTableView clearly returns 5. Printing out the number of sections from within cellForRowAtIndexPath shows the correct number, thus confirming that cellForRowAtIndexPath is simply not being called for all sections. What on earth is going on? I looked pretty hard for an answer to this question but could't find one. If this has already been answered please forgive me and point me in the correct direction.
My cellForRowAtIndexPath:
- (UITableViewCell *)tableView:(UITableView *)theTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [theTableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
switch (indexPath.section) {
case 0:
cell.textLabel.text = ticket.description;
break;
case 1:
cell.textLabel.text = ticket.ticketStatus;
break;
case 2:
cell.textLabel.text = ticket.priority;
break;
case 3:
cell.textLabel.text = ticket.customerOfficePhone;
break;
case 4: {
//This never ever gets executed
Comment *comment = [ticket.comments objectAtIndex:indexPath.row];
cell.textLabel.text = comment.commentContent;
break;
}
}
return cell;
}
My numberOfSectionsInTableView:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 5;
}
My numberOfRowsInSection:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
NSInteger numberOfRows;
if (section == 4) {
numberOfRows = [ticket.comments count];
}
else {
numberOfRows = 1;
}
return numberOfRows;
}
Any suggestions are appreciated. Thanks in advance.