##DAY11 UITableView编辑
##DAY11 UITableView编辑
每一个视图控制器都有一个编辑按钮,因为项目中编辑的应用场景非常多,所以系统预留了一个编辑按钮供我们使用
self.navigationItem.leftBarButtonItem = self.editButtonItem;
添加编辑:
[_tableView setEditing:YES animated:YES];
#pragma mark -------表视图移动操作---------
1、移动的第一步也是需要将表视图的编辑状态打开
setEditing:editing animated:
2、指定哪些行可以移动,默认都可以移动
-------UITableViewDataSource 协议的方法---------
tableView:canMoveRowAtIndexPath:
3、移动完成后要做什么事,怎么完成移动
-------UITableViewDataSource 协议的方法---------
tableView:moveRowAtIndexPath:toIndexPath:
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath {
//先记录一下原有位置的模型数据
Student *student = _dataArray[sourceIndexPath.row];
//引用计数+1
[student retain];
//删除原位置下的模型数据
[_dataArray removeObjectAtIndex:sourceIndexPath.row];
//在新位置将记录的模型数据添加到数据数组中
[_dataArray insertObject:student atIndex:destinationIndexPath.row];
[student release];
}
#pragma mark -------删除、添加数据---------
1、让将要执行删除、添加操作的表视图处于编辑状态
setEditing:editing animated:
2、指定表视图中哪些行可以处于编辑状态,此方法如果不重写,默认所有的行可以进行编辑
-------UITableViewDataSource 协议的方法---------
tableView:canEditRowAtIndexPath:
3、指定编辑样式,到底是删除还是添加,此方法如果不重写,默认是删除样式,用 | 表示多选
-------UITableViewDelegate 协议的方法---------
tableView:editingStyleForRowAtIndexPath:
4、提交,不管是删除还是提交,这个方法才是核心方法,当点击删除、或者添加按钮时,需要做什么事情,怎样才能完成删除或者添加操作,全部都在这里指定,点击删除按钮或提交按钮触发
-------UITableViewDataSource 协议的方法---------
tableView:commitEditingStyle:forRowAtIndexPath:
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
//1、表视图开始更新
[tableView beginUpdates];
//2、判断编辑样式
if(editingStyle == UITableViewCellEditingStyleDelete) {
//3、将该位置下的单元格删除
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
//4、删除数据数组中与该单元格绑定的数据
[_dataArray removeObjectAtIndex:indexPath.row];
}else if (editingStyle == UITableViewCellEditingStyleInsert) {
Student *student = _dataArray[indexPath.row];
//构建一个位置信息
NSIndexPath *index = [NSIndexPath indexPathForRow:0 inSection:0];
[tableView insertRowsAtIndexPaths:@[index] withRowAnimation:UITableViewRowAnimationTop];
[_dataArray insertObject:student atIndex:index.row];
}
//5、表视图结束更新
[tableView endUpdates];
}
##DAY11 UITableView编辑的更多相关文章
- iOS学习30之UITableView编辑
1. UITableView编辑 1> UITableView 编辑流程 2> UITableView 编辑步骤(四步) ① 第一步 : 让 TableView 处于编辑状态(在按钮点击事 ...
- IOS第七天(6:UiTableView编辑模式, 拖动位置 ,滑动删除)
**********UiTableView编辑模式, 拖动位置 ,滑动删除 #import "HMViewController.h" @interface HMViewContro ...
- UITableView编辑
UITableView 编辑步骤如下: 1.让TableView处于编辑状态 2.协议设定 2.1.确定Cell是否处于编辑状态 2.2.设定Cell的编辑样式(删除.添加) 2.3.编辑状 ...
- iOS学习之UITableView编辑
一.UITableView编辑 UITableView编辑(删除.添加)步骤: 让TableView处于编辑状态. 协议设定:1)确定Cell是否处于编辑状态:2)设定cell的编辑样式(删除.添加) ...
- UI:UITableView 编辑、cell重用机制
tableView编辑.tableView移动.UITableViewController tableView的编辑:cell的添加.删除. 使⽤场景: 删除⼀个下载好的视频,删除联系⼈: 插⼊⼀条新 ...
- UITableView 编辑模式(增加-删除-移动---自定义左滑 title)
- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typica ...
- UITableView编辑模式大全解
1.UITableView 的编辑模式 进入编辑模式 代码体现 // 设置 editing 属性 tableView?.editing = true // 这个设置的时候是有动画效果的 tableVi ...
- iOS - UITableView 编辑(cell的插入, 删除, 移动)
UITableView Cell的插入/删除 核心API Class : UITableView Delegate : UITableViewDataSource, UITableViewDelega ...
- UITableView编辑模式
UITableView有两种模式,普通模式和编辑模式.在编辑模式下可以对cell进行排序.删除.插入等等. 如何进入编辑模式 调用tableView的setEditing(editing: Bool, ...
随机推荐
- SVG 教程
SVG 意为可缩放矢量图形(Scalable Vector Graphics). SVG 使用 XML 格式定义图像. 现在开始学习 SVG! <html> <body> &l ...
- javascript数组去重算法-----2
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 复习day12-23
获取请求中的内容: request.getParameter(); get方式因为在地址栏所以需要转码: String name = new String(req.getparameter().get ...
- C# NameValueCollection集合 .
案例: NameValueCollection nameValueCollection = Request.Params;//获得连接地址中的所有参数 //获取各个参数,eg: ...
- 兼容 CommonJS 和 CommonJS-like规范(1~38)
CommonJS是服务器端模块的规范,Node.js采用了这个规范. 根据CommonJS规范,一个单独的文件就是一个模块.每一个模块都是一个单独的作用域,也就是说,在该模块内部定义的变量,无法被其他 ...
- SQL Server 备份维护计划
1. 创建维护计划:SSMS -> 管理 -> 维护计划 -> 新建维护计划 2. 添加子计划(备份计划) a) 每30分钟:事务日志备份 每天:差异备份 每周:完整备份 b) ...
- workspace & subProject & target
workspace & subProject & target http://blog.itpub.net/12231606/viewspace-1079867/ 最近新入一个项目组, ...
- 动态改变ComboBox下拉框的宽度
在C++Builder中有时下拉框的内容比较长,标准长度下根本显示不完,可以调用PostMessage()方法来实现 ::PostMessage(comb->Handle,CB_SETDROPP ...
- CentOS yum安装配置lnmp服务器(Nginx+PHP+MySQL)
1.配置防火墙,开启80端口.3306端口 vi /etc/sysconfig/iptables-A INPUT -m state --state NEW -m tcp -p tcp --dport ...
- < meta > 元素 概要
< meta > 元素 概要 标签提供关于HTML文档的元数据.元数据不会显示在页面上,但是对于机器是可读的.它可用于浏览器(如何显示内容或重新加载页面),搜索引擎(关键词),或其他 we ...