/** 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.最后对数据进行操作,刷新页面

iOS TabelViewCell 删除 编辑 插入的更多相关文章

  1. iOS:删除、插入、移动单元格

    删除.插入.移动单元格的具体实例如下:   代码如下: #import "ViewController.h" #define NUM 20 typedef enum { delet ...

  2. editActionsForRowAtIndexPath(iOS8) tableview编辑(删除、插入、移动)

    ios8 出来的左滑小菜单 可以自定义想要的按钮 (要求ios8以上) - (nullable NSArray<UITableViewRowAction *> *)tableView:(U ...

  3. UITableViewCell单元格的删除、插入、移动

    UITableViewDelegate的方法      设置编辑模式中得cell的编辑样式(删除或插入)      - (UITableViewCellEditingStyle)tableView:( ...

  4. 【转】 UITableViewCell的标记、移动、删除、插入

    原文: http://blog.csdn.net/duxinfeng2010/article/details/7725897 这篇文章是建立在 代码实现 UITableView与UITableView ...

  5. iOS 字符串删除 DOM

    iOS  string 删除 包含的 DOM NSMutableString *mutableString = [NSMutableString stringWithString:responseSt ...

  6. Xamarin iOS教程之编辑界面编写代码

    Xamarin iOS教程之编辑界面编写代码 Xamarin iOS的Interface Builder Interface Builder被称为编辑界面.它是一个虚拟的图形化设计工具,用来为iOS应 ...

  7. 【玩转Golang】slice切片的操作——切片的追加、删除、插入等

    一.一般操作 1,声明变量,go自动初始化为nil,长度:0,地址:0,nil func main(){ var ss []string; fmt.Printf("length:%v \ta ...

  8. javascript数组元素的添加、删除与插入以及参数数组的使用

    1.数组元素的添加 push方法在数组的尾部添加元素: var colorArray=new Array(); colorArray.push('red','black','yellow'); //这 ...

  9. mysql先删除后插入导致死锁

    所报的错误为:pymysql.err.OperationalError: (1213, 'Deadlock found when trying to get lock; try restarting ...

随机推荐

  1. day 02 python 基础

    1.day1作业讲解 题目答案见day1 2.格式化输出 %占位符,s:字符串,d:数字 %%只是单纯的显示%(显示的%是后面的) #格式化输出 # % s d # name = input('请输入 ...

  2. javaEE完整体系结构

    学习之前了解熟悉一下javaEE的完整体系结构会更有助于理解 https://segmentfault.com/a/1190000007090110

  3. 小程序二层嵌套循环数据:微信小程序开发(交流QQ群:604788754)

    WXML: <view class="martop15"> <view class="titlebox"> .二层嵌套循环 </v ...

  4. 软件测试第一次试验JUnit

    一.Junit, hamcrest以及eclemma的安装 对于Junit和hamcrest的安装,我并没有从下载Junit和hamcrest相关的jar包然后通过build path导入到项目中,而 ...

  5. 小谈对Python的认知与期望

    18级新生,在大学之前并未接触过程序语言编程,在众多语言编程中只对C语言有个名字上认知.在上个学期初次了解到Python语言,计算机老师表示Python是现在编程语言中如雨后春笋般的发展飞速的计算机语 ...

  6. 聊聊大学期间的我是怎样学习Linux系统的

    高考成绩并不是那么的理想,本科是个普通的二本院校,来到学校之后,整个人其实很迷茫,当时对大学的专业真的是一点都不了解,也不知道自己对哪方面感兴趣,最后选择的专业是电子方面的,其实当时选择专业的时候对电 ...

  7. python中一些传参事情

    #一个参数的传参 def hello(a):    print(a+'王彦军你好')hello('hello')''' #2个参数的 def ab(a,b):    print(a+'你好')    ...

  8. JS 判断两个时间的大小(可自由选择精确度:天,小时,分钟,秒)

    //可自由选择精确度 如:签到时间:2018-11-07 11:00:00 签退时间:2018-11-07 10:59:59 //判断时间先后 //统一格式 var a = $("#fdtm ...

  9. npx

    npx 是什么? npm v5.2.0引入的一条命令(npx),引入这个命令的目的是为了提升开发者使用包内提供的命令行工具的体验. 举例:使用create-react-app创建一个react项目. ...

  10. ubuntu16.04安装pycharm

    Ubuntu16.04下,默认安装了python2.7和python3.5,在终端下,输入“Python”  或“python3”可查看具体版本. 1.安装PyCharm前,先配置PyCharm的JD ...