UITableView有两种模式,普通模式和编辑模式。在编辑模式下可以对cell进行排序、删除、插入等等。

  1. 如何进入编辑模式
    调用tableView的setEditing(editing: Bool, animated: Bool)方法。

    • 进入编辑模式以后发生了什么

      • 向每个cell发送setEditing:animated:方法

      • 进入编辑模式以后cell的变化


        普通模式下cell的contentview的bounds就是cell的bounds.
        编辑模式下,cell有三部分组成,左边的Editing control,中间的contentview,右边的reordering control。这时contentview的位置和大小都发生了变化。
        所以一般情况下,把需要展示的东西加到contentview上,而不是cell上。文档是也有说明。

        The content view of a UITableViewCell object is the default superview for content displayed by the cell. If you want to customize cells by simply adding additional views, you should add them to the content view so they will be positioned appropriately as the cell transitions into and out of editing mode

  • 删除模式

    • 指定模式为删除模式

      func tableView(tableView: UITableView, editingStyleForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCellEditingStyle {
      return .Delete
      }
    • 定制删除提示语

      func tableView(tableView: UITableView, titleForDeleteConfirmationButtonForRowAtIndexPath indexPath: NSIndexPath) -> String? {
      return "我删除啦"
      }

      这时,cell右侧又多出来一个部分,叫做UITableViewCellDeleteConfirmtionView,不同的删除提示语,长度不一样。

  • 插入模式

    • 将style设为insert就好

      func tableView(tableView: UITableView, editingStyleForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCellEditingStyle {
      return .Insert
      }
    • 展示右边的排序按钮

      func tableView(tableView: UITableView, moveRowAtIndexPath sourceIndexPath: NSIndexPath, toIndexPath destinationIndexPath: NSIndexPath) {
      //do something
      }

      实现这个方法就好,即使什么都不做

  • 展示多选按钮

        tableView?.allowsMultipleSelectionDuringEditing = true
    tableView?.tintColor = UIColor.blackColor()

  • swipe to delete

    • 实现相应的代理方法

      func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
      }

      这个方法里不能调用setEditing(_:animated:)方法

    • tableView(_:editingStyleForRowAt:)方法必须返回delete

UITableView编辑模式的更多相关文章

  1. IOS第七天(6:UiTableView编辑模式, 拖动位置 ,滑动删除)

    **********UiTableView编辑模式, 拖动位置 ,滑动删除 #import "HMViewController.h" @interface HMViewContro ...

  2. UITableView 编辑模式(增加-删除-移动---自定义左滑 title)

    - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typica ...

  3. UITableView编辑模式大全解

    1.UITableView 的编辑模式 进入编辑模式 代码体现 // 设置 editing 属性 tableView?.editing = true // 这个设置的时候是有动画效果的 tableVi ...

  4. UITableView 编辑模式(增加-删除-移动---自定义左滑 title) xib cell

    参考:  http://www.open-open.com/lib/view/open1430008922468.html - (void)viewDidLoad { [super viewDidLo ...

  5. UITableView的编辑模式

    UITableView可以分普通模式和Editing模式两种,这里我们着重讨论Editing模式,Editing模式中又分三种操作:Insert.Delete. Reallocted.Insert和D ...

  6. 让UITableView进入编辑模式

    1.UITableView对象有一个editing属性,设为YES时,该对象会进入编辑模式(editing mode).表格视图进入编辑模式后,用户可以管理表格中得行,如改变行的排列顺序.增加行或删除 ...

  7. iOS开发——UI进阶篇(四)tableView的全局刷新,局部刷新,左滑操作,左滑出现更多按钮,进入编辑模式,批量删除,自定义批量删除

    首先创建项目,在storyboard如下布局控件,设置好约束 然后创建cell模型类XMGWineCell数据模型类XMGWine创建UITableView,设置数据源协议,实现数据源方法懒加载数据这 ...

  8. IOS第13天(3,私人通讯录,登陆状态数据存储,数据缓存, cell的滑动删除,进入编辑模式,单个位置刷新 )

    *****联系人的界面的优化 HMContactsTableViewController.m #import "HMContactsTableViewController.h" # ...

  9. ios之UITableViewController(二) tableView的编辑模式

    tableView的编辑模式 表视图可以进入编辑模式,当进入编辑模式就可以进行删除.插入.移动单元等操作 效果图: 让表视图进入编辑模式,进入编辑模式的方法有两种,一种是使用导航栏的edit 按钮,另 ...

随机推荐

  1. Hibernate其它API

    ----------------siwuxie095 (一)Query 1.使用 Query 对象执行查询操作,不需要写 sql 语句,但是要写 hql 语句 (1)hql:即 Hibernate Q ...

  2. 钉钉开发笔记(六)使用Google浏览器做真机页面调试

    注: 参考文献:https://developers.google.com/web/ 部分字段为翻译文献,水平有限,如有错误敬请指正 步骤1: 从Windows,Mac或Linux计算机远程调试And ...

  3. spring4-3-AOP-面向切面编程

    AOP常用的两个用户:日志和验证.也就是程序追踪和数据验证. 直接使用代码实现,距离如下:

  4. 多视几何——三角化求解3D空间点坐标

    VINS-Mono / VINS-Fusion中triangulatePoint()函数通过三角化求解空间点坐标,代码所体现的数学描述不是很直观,查找资料,发现参考文献[1]对这个问题进行详细解释,记 ...

  5. [C++] struct memory allocation

    MAX-byte alignment (最大单位对齐) typedef struct user USER; typedef struct employee E; struct user{ ]; //t ...

  6. tomcat启动报错:java.lang.IllegalArgumentException: Document base D:\apache-tomcat-6.0.45\webapps\activiti-explorer does not exist or is not a readable directory

    java.lang.IllegalArgumentException: Document base D:\apache-tomcat-6.0.45\webapps\erp does not exist ...

  7. java解决跨域

    方法中response.setHeader("Access-Control-Allow-Origin", "https://ding.taozugong.com" ...

  8. Discuz!X2截屏控件手动安装教程-Xproer.ScreenCapture

    版权所有 2009-2015 荆门泽优软件有限公司 保留所有权利 官方网站:http://www.ncmem.com 官方博客:http://www.cnblogs.com/xproer 产品首页:h ...

  9. MongoDBAppender

    分三步: 1. client 2. appender 3. 配置文件 logback-test.xml <configuration> <appender name="MO ...

  10. Linux 下几个重要目录解释

    linux下把所有的东西都当作文件的,,一个分区想要使用就需要挂载到一个文件夹上,那这个文件夹就叫挂载点,像常用的把 设备/dev/cdrom挂载到/mnt,,,你想问的应该是linux的各目录的解释 ...