如何将所选的customTableCellA替换为customTableCellB

时间:2014-04-23 01:22:48

标签: ios uitableview

如何将所选的customTableCellA替换为customTableCellB

  • 我已经有一个使用customTableCellAs的表视图
  • 我想在选择customTableCellB时将其替换为customTableCellA。
  • customTableCellB比customTableCellA
  • 高50像素

如何正确实施?

1 个答案:

答案 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];
}