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.
Ah-ha! I figured it out. I had forgotten that I had hard coded the frame for my table view and added it as a subview with the scroll disabled to a scroll view. Unfortunately both the scroll view and the tableview were too small in terms of height to hold the fifth section which i suppose was the reason cellForRowAtIndexPath was being called for all sections except the fifth one. Readjusting the height of my table view and scroll view to be a little bigger has solved my problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With