Add a tulajdonság, hogy nyomon követhesse a kijelölt cella
@property (nonatomic) int currentSelection;
Állítsa a sentinel értéket (például) viewDidLoad, hogy megbizonyosodjon arról, hogy az UITableViewelindul a „normális” helyzetben
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
//sentinel
self.currentSelection = -1;
}
A heightForRowAtIndexPathbeállíthatja a kívánt magasságot a kijelölt cella
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
int rowHeight;
if ([indexPath row] == self.currentSelection) {
rowHeight = self.newCellHeight;
} else rowHeight = 57.0f;
return rowHeight;
}
A didSelectRowAtIndexPathelmentheti az aktuális kiválasztási és mentse a dinamikus magasság, ha szükséges
- (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];
}
}
A didDeselectRowAtIndexPathkijelölés beállításához index vissza a sentinel érték és animálni a cella visszatér a normál forma
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath {
// do things with your cell here
// sentinel
self.currentSelection = -1;
// animate
[tableView beginUpdates];
[tableView endUpdates];
}
}