Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITableViewCell resize height WITHOUT changing it's content lauout

This is killing me!
I have a UITableView with cells that has an image, name and phone number in them.
Look here:

enter image description here

Now, I want to expend the cell's height when touching it so I can add some buttons in there. When I expend the cell, I also change it's bg image (to a higher one).
I do it using [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; and it works nice, animates the cell down smoothly, except that it also changes the cell's content:

Cell's content resized :(

Anything I can do so the content will stay as it was after cell resizing?

BTW, i did try using,
[_tableView beginUpdates];
[_tableView endUpdates];
but the cell just "jumped" to it's new height so I gave it up.

like image 387
Gal Avatar asked Dec 17 '25 04:12

Gal


2 Answers

You can create two custom cells one before expansion and another one for expanded cell. when you touch the cell store the selected cell indexpath and while reloading the table, in cellForRowAtIndexPath: check the indexpath and load cell accordingly.

like image 68
AMohan Avatar answered Dec 19 '25 22:12

AMohan


You need to be aware of the layouting of the contentView.

If you use Autolayout, check your constraints (cell.contentView.constraints). If you use UIViewAutoresizing, set correct autoresizingMasks (cell.contentView.autoresizingMask) for all subviews of contentView. You could also try to turn off autoResizing (cell.contentView.autoresizesSubviews = NO), but this will likely result in wrong results.

Also I'm wondering, why there is an arrow in the cell backgroundImage? Probably you should use other images too.

like image 35
calimarkus Avatar answered Dec 19 '25 21:12

calimarkus