Adăugați o proprietate pentru a ține evidența celulei selectate
@property (nonatomic) int currentSelection;
Setați - l la o valoare santinelă (de exemplu) viewDidLoad, pentru a se asigura că UITableViewîncepe în poziția „normală“
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
//sentinel
self.currentSelection = -1;
}
În heightForRowAtIndexPathputeți seta înălțimea dorită pentru celula selectată
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
int rowHeight;
if ([indexPath row] == self.currentSelection) {
rowHeight = self.newCellHeight;
} else rowHeight = 57.0f;
return rowHeight;
}
În didSelectRowAtIndexPathsalvați selecția curentă și de a salva o înălțime dinamică, dacă este necesar
- (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];
}
}
In didDeselectRowAtIndexPathset indicele de selecție înapoi la valoarea de santinelă și anima celula înapoi la forma normală
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath {
// do things with your cell here
// sentinel
self.currentSelection = -1;
// animate
[tableView beginUpdates];
[tableView endUpdates];
}
}