29.table view的编辑模式
来源:互联网 发布:网络小三毛图片 编辑:程序博客网 时间:2024/05/29 08:22
//开启编辑模式:self.tableView.editing = YES;// 用于告诉系统开启的编辑模式是什么模式- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{ if (indexPath.row % 2 == 0) { return UITableViewCellEditingStyleInsert; }else { return UITableViewCellEditingStyleDelete; }}// 只在在tableview的编辑模式下才有添加// 只要实现该方法, 手指在cell上面滑动的时候就自动实现了删除按钮// commitEditingStyle: 传入提交的编辑操作(删除/添加)// forRowAtIndexPath: 当前正在编辑的行- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{ if (UITableViewCellEditingStyleDelete == editingStyle) { // 1.修改数据 [self.contatcs removeObjectAtIndex:indexPath.row]; // 2.刷新表格 // 该方法用于删除tableview上指定行的cell // 注意:使用该方法的时候,模型中删除的数据的条数必须和deleteRowsAtIndexPaths方法中删除的条数一致,否则会报错 [self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationTop]; }else if (UITableViewCellEditingStyleInsert == editingStyle) { // 1.修改数据 NJContatc *c = [[NJContatc alloc] init]; c.name = @"xff"; c.phoneNumber = @"123456"; [self.contatcs insertObject:c atIndex:indexPath.row + 1]; NSIndexPath *path = [NSIndexPath indexPathForRow:indexPath.row + 1 inSection:0]; // 注意点:数组中插入的条数必须和tableview界面上插入的cell条一致 // 否则程序会报错 [self.tableView insertRowsAtIndexPaths:@[path] withRowAnimation:UITableViewRowAnimationBottom]; }}[cell.contentView addSubView: view];在编辑模式的时候才不会出错!
0 0
- 29.table view的编辑模式
- table的编辑模式(多选,插入,删除)
- table的编辑.删除
- portlet编辑后修改模式为view的方法
- OC-向table中添加数据&table的编辑模式&通过封装自定义cell
- Android动态切换多个View的可编辑/不可编辑模式
- table,view,mview(multiliazed view)的比较
- 干净的table view 代码
- 整理 Table View 的代码
- 整洁的 Table View 代码
- 整洁的 Table View 代码
- 整洁的 Table View 代码
- 关于Table View的介绍
- 模板的编辑模式
- tableView的编辑模式
- UITableView的编辑模式
- UITableView的编辑模式
- SWT的Table表格可编辑单元格
- 漫谈 Clustering (番外篇): Vector Quantization
- 第十二周 项目4-点,圆的关系
- servlet学习笔记8——ServletContext的讲解和使用
- iOS添加自定义自体 [UIFont fontWithName: size:](英文有效)
- 在服务中启动所需要的应用程序
- 29.table view的编辑模式
- CTCI---8.2.2
- 机器学习基础 II
- 漫谈 Clustering (3): Gaussian Mixture Model
- android-进阶(1)- 图片的横向滑动,点击查看图片
- asmack最新jar包地址
- Handling Keyboard Input
- Nginx在centos6.5下的安装和反向代理简单配置
- c# AES加解密