UITableView编辑模式
UITableView有两种模式,普通模式和编辑模式。在编辑模式下可以对cell进行排序、删除、插入等等。
如何进入编辑模式
调用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编辑模式的更多相关文章
- IOS第七天(6:UiTableView编辑模式, 拖动位置 ,滑动删除)
**********UiTableView编辑模式, 拖动位置 ,滑动删除 #import "HMViewController.h" @interface HMViewContro ...
- UITableView 编辑模式(增加-删除-移动---自定义左滑 title)
- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typica ...
- UITableView编辑模式大全解
1.UITableView 的编辑模式 进入编辑模式 代码体现 // 设置 editing 属性 tableView?.editing = true // 这个设置的时候是有动画效果的 tableVi ...
- UITableView 编辑模式(增加-删除-移动---自定义左滑 title) xib cell
参考: http://www.open-open.com/lib/view/open1430008922468.html - (void)viewDidLoad { [super viewDidLo ...
- UITableView的编辑模式
UITableView可以分普通模式和Editing模式两种,这里我们着重讨论Editing模式,Editing模式中又分三种操作:Insert.Delete. Reallocted.Insert和D ...
- 让UITableView进入编辑模式
1.UITableView对象有一个editing属性,设为YES时,该对象会进入编辑模式(editing mode).表格视图进入编辑模式后,用户可以管理表格中得行,如改变行的排列顺序.增加行或删除 ...
- iOS开发——UI进阶篇(四)tableView的全局刷新,局部刷新,左滑操作,左滑出现更多按钮,进入编辑模式,批量删除,自定义批量删除
首先创建项目,在storyboard如下布局控件,设置好约束 然后创建cell模型类XMGWineCell数据模型类XMGWine创建UITableView,设置数据源协议,实现数据源方法懒加载数据这 ...
- IOS第13天(3,私人通讯录,登陆状态数据存储,数据缓存, cell的滑动删除,进入编辑模式,单个位置刷新 )
*****联系人的界面的优化 HMContactsTableViewController.m #import "HMContactsTableViewController.h" # ...
- ios之UITableViewController(二) tableView的编辑模式
tableView的编辑模式 表视图可以进入编辑模式,当进入编辑模式就可以进行删除.插入.移动单元等操作 效果图: 让表视图进入编辑模式,进入编辑模式的方法有两种,一种是使用导航栏的edit 按钮,另 ...
随机推荐
- C++ const引用
(1) 在实际的程序中,引用主要被用做函数的形式参数--通常将类对象传递给一个函数.引用必须初始化. 但是用对象的地址初始化引用是错误的,我们可以定义一个指针引用. 1 int ival ...
- mysql oracle计算两点之间的距离
mysql函数: SET FOREIGN_KEY_CHECKS=0; DROP FUNCTION IF EXISTS `getDistance`;DELIMITER ;;CREATE DEFINER= ...
- 使用jquery修改表单的提交地址
基本思路: 通过使用jquery选择器得到对应表单的jquery对象,然后使用attr方法修改对应的action 示例程序一: 默认情况下,该表单会提交到page_one.html 点击button之 ...
- uc_authcode()
//解用户标识码public static function setAuthCode($auth){ //对 base64 编码的 data 进行解码. $auth = base64_decode($ ...
- pcl知识
1.pcl/io/pcd_io.h pcl/io/ply_io.h pcl::PLYReader reader; pcl::PCDWriter pcdwriter; 读取ply pcd 2.voidl ...
- css确定取消 悬浮底部样式 和 金额 后缀
.blockquote-bottom { width: 100%; position: fixed; margin: 0; bottom: 0; left: 0; text-align: center ...
- java/rabbitmp发布订阅示例(转)
原文:http://www.cnblogs.com/tinmh/p/6134875.html 发布/订阅模式即生产者将消息发送给多个消费者. 下面介绍几个在发布/订阅模式中的关键概念-- 1. Exc ...
- C# 进程Process基本的操作说明
public int CallPhoneExe(string arg) //arg为进程的命令行参数 { WaitHandle[] waits =new WaitHandle[2]; //定义两个Wa ...
- C#延迟执行
借鉴于该篇博客:http://kb.cnblogs.com/page/42581/ 先看两个方法 public class YieldClasses { public static IEnumerab ...
- SSH2免密码登录OpenSSH
OpenSSH免密码登录SSH2http://blog.csdn.net/aquester/article/details/23836245 两个SSH2间免密码登录http://blog.csdn. ...






