एक संपत्ति चयनित सेल का ट्रैक रखने में जोड़े
@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];
}
}