maltalef
maltalef

Reputation: 1565

UITableViewCell mysteriously changing heights

I have a xib with an UITableView (style: grouped), and a few UITableViewCells also on the xib connected as an outlet collection.

I return these cells from tableView:cellForRowAtIndexPath: in a fashion very similar to what is described in the Table View Programming Guide (The Technique for Static Row Content).

Then I have another IBOutlet cell, with a different height, and a button that toggles a flag and reloads always the same row (reloadRowsAtIndexPaths:withRowAnimation:).

cellForRowAtIndexPath for that exact row returns either one of the normal cells from the outlet collection or that special cell (depending on the flag).

heightForRowAtIndexPath also takes the height of the appropriate cell and returns it using the same 'logic', I've NSLogged it to death;

Now what happens is each time I press the button, the first and last row add one pixel to their heights! Anyone can think what's happening?

I uploaded a sample project with just this: http://www.mediafire.com/?sc22v0c6w11b4l6

Upvotes: 2

Views: 90

Answers (2)

Neo
Neo

Reputation: 2807

This problem has happened only when your tableViewStyle is grouped... so you can either use plain style or return hardcode value

if (indexPath.row == kBigCellRowNum && self.showTheBigCell){

    return self.bigCell.frame.size.height;

}

else{

    return 44;

}

Upvotes: 0

Resh32
Resh32

Reputation: 6590

Replacing:

return (UIView *)[self.cells objectAtIndex:indexPath.row] bounds].size.height;

by

return 30;

Fixes your problem.

I think that the redraw of your larger cell modifies the whole table size, and for some reason recomputes the first and last cells to higher size.

Upvotes: 1

Related Questions