ios UITableViewcell上的按钮插入cell

1.我的按钮是在tabView的section上的,点击一下插入俩个cell,二次点击删除这俩个cell
isInsert是按钮的点击状态
countArr是存放我本地图片’名称’的数组,便于刷新的时候从数组中取出名称给本地图片命名
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section ==0) {
        return 4;
    }else if (section == 1){
        return countArr.count;
    }else if(section == 2){
        return 1;
    }
    return 0;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *mycell = @"cell";
    //cellForRowAtIndexPath 这个方法不是重用,不要随便用,我这界面内容少,而且大部分是死的,所以我采用的
    HTApplyCoinsTableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    if (cell == nil) {
        cell = [[HTApplyCoinsTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:mycell];
    }
     if (indexPath.section == 1){
        cell.labTitle.hidden = YES;
        cell.textfield.hidden = YES;
        cell.imgdisplay.hidden = NO;
        cell.imgdisplay.image = [UIImage imageNamed:countArr[indexPath.row]];
    }
    //cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}
#pragma mark 按钮的点击  重点就在这里面哈
-(void)btnDisplayCertificate
{
    if (!isInsert) {
        isInsert = YES;
        NSMutableArray *indexPaths = [[NSMutableArray alloc] init];
        for (int i=0; i<2; i++) {
            NSIndexPath *indexPath = [NSIndexPath indexPathForRow:i inSection:1];
            NSString *picStr = [NSString stringWithFormat:@"图%d",i+1];
            NSLog(@"img == %@",picStr);
            [countArr addObject:picStr];
            [indexPaths addObject: indexPath];
        }
        //此处是插入 俩个cell
        [self.tableView insertRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationNone];
    }else{
        isInsert = NO;
        NSMutableArray *indexPaths = [[NSMutableArray alloc] init];
        [countArr removeAllObjects];
        for (int i=0; i<2; i++) {
            NSIndexPath *indexPath = [NSIndexPath indexPathForRow:i inSection:1];
            [indexPaths addObject: indexPath];
        }
        //此处是删除 俩个cell
        [self.tableView deleteRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationNone];
        [self.tableView beginUpdates];
        [self.tableView endUpdates];
    }
}
希望能对你们有帮助
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值