/** TableView 进入或退出编辑状态(TableView 方法). */
- (void)setEditing:(BOOL)editing animated:(BOOL)animate{     /*首先调用父类的方法*/
    [super setEditing:editing animated:animated];
    /*使tableView出于编辑状态*/
    [self.tableView setEditing:editing animated:animated];
}
 
/** 确定哪些行的cell可以编辑 (UITableViewDataSource协议中方法). */
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath{
if (0 == indexPath.row)  {
return No; /*第一行不能进行编辑*/
} else {
return Yes;
}
}
 
/** 设置某一行cell的编辑模式 (UITableViewDelegate协议中方法). */
- (TableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
  

  if (indexPath.row > 10){
    return UITableViewCellEditingStyleInsert;
    }else{
    return UITableViewCellEditingStyleDelete;
  }
}

/** 提交编辑状态 (UITableViewDataSource协议中方法). */
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{
  

    /** 点击 删除 按钮的操作 */
    if (editingStyle == UITableViewCellEditingStyleDelete) {
    /**< 判断编辑状态是删除时. */ /** 1. 更新数据源(数组): 根据indexPaht.row作为数组下标, 从数组中删除数据. */
    [self.arr removeObjectAtIndex:indexPath.row];
    /** 2. TableView中 删除一个cell. */
    [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationRight];
    }
    /** 点击 +号 图标的操作. */
    if (editingStyle == UITableViewCellEditingStyleInsert) {
      /**< 判断编辑状态是插入时. */ /** 1. 更新数据源:向数组中添加数据. */
      [self.arr insertObject:@"abcd" atIndex:indexPath.row]; /** 2. TableView中插入一个cell. */
      [tableView insertRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
   }
}

/** 提交编辑状态 (UITableViewDataSource协议中方法). */
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath

/** 插入 cell (UITableView 方法). */
- (void)insertRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation

/** 删除 cell (UITableView 方法). */
- (void)deleteRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation

上面的需求思路:

        1.tableView 要进入可编辑状态(根据自己的需要)

        2.更具自己需要,删除,或者,插入,指定Cell

        3.最后对数据进行操作,刷新页面

最新文章

  1. Delphi_02_Delphi程序的结构
  2. day4总结
  3. JSPatch常见问题解答
  4. UITableView 使用
  5. Laravel学习
  6. C# 7.0 新特性4: 返回引用
  7. ubuntu 设置静态ip
  8. Spring源码:IOC原理解析(一)
  9. IPV4/IPV6网络地址相关知识
  10. 【笔记】【VSCode】Windows下VSCode编译调试c/c++
  11. win10 uwp 修改Pivot Header 颜色
  12. Kotlin——从无到有系列之高级篇(一):Lambda表达式
  13. js获取当前时间并实时刷新
  14. Xamarin常见问题
  15. python中的os.listdir()函数
  16. java post json sample
  17. FortiGate日志设置
  18. 题解——loj6280 数列分块入门4 (分块)
  19. 学JS的心路历程-Promise(一)
  20. jpa-入门测试

热门文章

  1. 微信小程序电商实战(-)商城首页
  2. 什么样的类才算是一种可重用的组件,即JavaBean?
  3. Java 有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第三个月后每个月又生一对兔子,假如兔子都不死,问每个月的兔子总数为多少?
  4. spring boot开发环境搭建(三)
  5. java入门day03
  6. 【转】Linux的nm查看动态库和静态库的符号
  7. MYSQL+PHP的学习之路
  8. Java语法基础学习DayTwentyOne(网络编程)
  9. PCA降维—降维后样本维度大小
  10. 读取HeidiSQL 配置文件中的密码