- (UITableViewCell *)tableView:... cellForRowAtIndexPath:... {
// init and sanity check
if (indexPath.row == 0) {
// make cell look like a section header
// easier and less complex than using a custom header view
NSLog(@"header");
// should prove that only four cells get the bg image
// and yet, almost every time the table is reloaded
// one more cell unexpectedly gets the background
// without putting another line in the debugger
} else {
// normal cells after row 0
// BUG: some of these are getting the row 0 background
NSLog(@"row");
// firing exactly the right number of times --
// once for each row with an index greater than 0
// so why are some of these cells getting the header bg?
// when these cells get the headers' contents
// they behave exactly as one would expect
// except that they should be the normal rows
}
// misc stuff, not causing problems
return cell;
}
Short of forcing the user to completely relaunch the app just to have different data dumped into the table, I can’t figure out how to fix the bug.
The problem is less severe if I collapse every section (that is, empty the expandedSections set and reload, leaving only the pseudo-headers visible), but it doesn’t go away.
Edit:
Initial load: screenshot
After reloading: screenshot
Links instead of images because it’s an iPad app.
Using some dummy content for testing.
Is this any help? I know there needs to be more code for serious help, but I don’t know what else to add, short of a link to the code for the entire view.
Have you tried setting a different cell identifier for the first cell and another one for the rest of them?
The tableView reuses the same cell type when creating new cells so it might get them mixed up. By using different cell identifiers for each type, it will know exactly when to use each cell.