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";
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]];
}
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];
}
[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];
}
[self.tableView deleteRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationNone];
[self.tableView beginUpdates];
[self.tableView endUpdates];
}
}
希望能对你们有帮助