I have only one cell
with a button in a tableview
. The cell
height is defined in
tableView:tableView:heightForRowAtIndexPa
Define a property and @synthesize
it:
@property (retain, nonatomic) NSIndexPath* selectedRowIndex;
Override didSelectRowAtIndexPath
and heightForRowAtIndexPath
methods:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if(selectedRowIndex && indexPath.row == selectedRowIndex.row) {
//[_yourTableView deselectRowAtIndexPath:indexPath animated:YES]; If you only want the cell to get bigger
selectedRowIndex = nil;
}
else { self.selectedRowIndex = [indexPath retain]; }
[tableView beginUpdates];
[tableView endUpdates];
}
- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
if (tableView == _yourTableView) {
if(selectedRowIndex && indexPath.row == selectedRowIndex.row){
return 80;
}
// Cell isn't selected so return single height
return 40;
}
else return 0;
}
Because of the beginUpdates and endUpdates lines this should animate the cell height.