思路:点击按钮时,改变旧cell、新cell高度,再重新加载指定行。
代码:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if (_selectedIndexPath.isEqual(indexPath)) {
return BIG_HEIGHT; // 展开后高度
} else {
return DEFAULT_HEIGHT; // 默认高度
}
}
- (void)changeButtonClick:(id)sender {
NSIndexPath *indexPath = [self indexPathForButton:sender]; // 需要自己实现
NSArray *indexPaths = _selectedIndexPath ? @[indexPath, _selectedIndexPath] : @[indexPath];
[self.tableView reloadRowsAtIndexPaths:indexPaths];
_selectedIndexPath = indexPath;
}