ios UITableViewcell上的按钮插入cell
来源:互联网 发布:云技术与大数据 编辑:程序博客网 时间:2024/05/20 05:09
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
- ios UITableViewcell上的按钮插入cell
- iOS 点击UITableViewCell上的按钮获取当前cell和行数
- iOS 自定义UITableViewCell上添加UIButton按钮实现选中的是哪个按钮对应的cell,用代理实现。
- iOS 点击UITableViewCell上的控件获取对应的cell
- UITableViewCell的操作(增加cell,删除cell,插入cell)
- IOS--UITableViewCell上的按钮点击事件处理
- UITableViewCell左滑动删除 和cell上按钮的点击事件
- UITableViewCell上的cell与content…
- (0066)iOS开发之UITableViewCell上子控件通过superView找对应的cell的探究
- 获取UITableViewCell中的按钮所在的cell的indexPath.row
- iOS点击cell上的某一个按钮时 如何获得点击的是第几个cell
- 如何得到自定义UITableViewCell中的按钮所在的cell
- 自定义UITableViewCell中获取按钮所在Cell的indexPath
- 自定义UITableViewCell上的delete按钮
- 自定义UITableViewCell上的delete按钮
- 自定义UITableViewCell上的delete按钮
- 自定义UITableViewCell上的delete按钮
- 自定义UITableViewCell上的delete按钮
- 检测nginx脚本
- Android项目结构-Gradle理解一
- Xcode下配置UNIX网络编程(UNP)环境
- 无参数传参
- 八数码问题(typedef int state[9];)(多种解法)
- ios UITableViewcell上的按钮插入cell
- Mysql函数记录
- 创建一个不显示窗口的Win32程序
- mkdir命令
- 严重 A child container failed during start——Caused by: java.lang.NoClassDefFoundError: org/springframe
- SpringMVC后台实现跨域支持
- 71 linux usb设备驱动
- mos文章将ogg捕捉模式由普通模式转换成集成捕捉
- keepalived+lvs无法访问vip或访问超时