Přidejte vlastnost sledovat vybrané buňky
@property (nonatomic) int currentSelection;
Nastavte ji na hodnotu sentinelové v (například) viewDidLoad, aby se ujistil, že UITableViewzačíná v ‚normální‘ polohy
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
//sentinel
self.currentSelection = -1;
}
V heightForRowAtIndexPathmůžete nastavit výšku chcete pro vybrané buňky
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
int rowHeight;
if ([indexPath row] == self.currentSelection) {
rowHeight = self.newCellHeight;
} else rowHeight = 57.0f;
return rowHeight;
}
V didSelectRowAtIndexPathuložit aktuální výběr a uložení dynamickou výšku, v případě potřeby
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// do things with your cell here
// set selection
self.currentSelection = indexPath.row;
// save height for full text label
self.newCellHeight = cell.titleLbl.frame.size.height + cell.descriptionLbl.frame.size.height + 10;
// animate
[tableView beginUpdates];
[tableView endUpdates];
}
}
Při didDeselectRowAtIndexPathnastavení indexu výběr zpět na hodnotu sentinelové a oživit buňku zpět do normální formy
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath {
// do things with your cell here
// sentinel
self.currentSelection = -1;
// animate
[tableView beginUpdates];
[tableView endUpdates];
}
}