views:

335

answers:

2

I know it is possible to set the height of all rows in a UITable but is it possible to set one row to be bigger than the others. For example when the user touches on the cell with 2 fingers I want the cell to expand and show a description. But only that cell. Is that possible without overlapping the cells below it?

+1  A: 

Use the UITableViewDelegate method heightForRowAtIndexPath

Say that your data model stored objects that have a height property:

 - ( void ) changeHeightForRowAtIndexPath: ( NSIndexPath *) indexPath ( NSInteger ) height {
    [ myData objectAtIndex: indexPath.row ].height = height;
    [ myTableView reloadRowsAtIndexPaths: [ NSArray arrayWithObject: indexPath ] withRowAnimation: UITableViewRowAnimationNone ];
 }
Jacob Relkin
But I won't be able to change the height of the row when I like? Only when the TableViewController "asks" for it
Jonathan
Just call `reloadRowsAtIndexPaths` with a one-element `NSArray`.
Jacob Relkin
You want to persist cell height?
Jacob Relkin
Jonathan: Just return the correct height in `-heightForRowAtIndexPath:` and you'll be all set.
Jeff Kelley
+1  A: 

Override this method - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath.

http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UITableViewDelegate_Protocol/Reference/Reference.html#//apple_ref/occ/intfm/UITableViewDelegate/tableView:heightForRowAtIndexPath:

Aleksejs
He is asking for an animation that dynamically changes the height. heightForRowAtIndexPath is run prior to the table setup and won't change the height with user interaction.
Michael
Yep... You are right. My answer doesn't cover his needs.
Aleksejs