如何将所选的customTableCellA替换为customTableCellB
如何正确实施?
答案 0 :(得分:0)
试试这个,
创建@property
数组NSMutableArray *selectedIndexPathArray
并在viewDidLoad
中实例化,然后
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
CGFloat cellHeight = //customTableCellA height
if ([self.selectedIndexPathArray containsObject:indexPath]) {
cellHeight = //customTableCellB height
} else {
cellHeight = //customTableCellA height
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
...
if ([self.selectedIndexPathArray containsObject:indexPath]) {
//Load customTableCellB
} else {
//Load customTableCellA
}
//Other code
...
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([self.selectedIndexPathArray containsObject:indexPath]) {
//If you want to remove the selection in second touch, do
//[self.selectedIndexPathArray removeObject:indexPath];
} else {
[self.selectedIndexPathArray addObject:indexPath];
}
[tableView beginUpdates];
[tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationNonne];
//Select appropriate UITableViewRowAnimation
[tableView endUpdates];
}