Προσθέστε ένα ακίνητο για να παρακολουθείτε το επιλεγμένο κελί
@property (nonatomic) int currentSelection;
Ρυθμίστε σε μια τιμή δείκτες (για παράδειγμα) viewDidLoad, για να βεβαιωθείτε ότι οι UITableViewξεκινά στην «κανονική» θέση
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
//sentinel
self.currentSelection = -1;
}
Σε heightForRowAtIndexPathμπορείτε να ρυθμίσετε το ύψος που θέλετε για το επιλεγμένο κελί
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
int rowHeight;
if ([indexPath row] == self.currentSelection) {
rowHeight = self.newCellHeight;
} else rowHeight = 57.0f;
return rowHeight;
}
Σε didSelectRowAtIndexPathμπορείτε να αποθηκεύσετε την τρέχουσα επιλογή και να αποθηκεύσετε μια δυναμική ύψος, εάν απαιτείται
- (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];
}
}
Σε didDeselectRowAtIndexPathρυθμίσετε το δείκτη επιλογής πίσω στην τιμή-δείκτες και την κίνηση του κυττάρου πίσω στην κανονική μορφή
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath {
// do things with your cell here
// sentinel
self.currentSelection = -1;
// animate
[tableView beginUpdates];
[tableView endUpdates];
}
}