##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, ...
随机推荐
- Advanced Fruits(好题,LCS的模拟)
Advanced Fruits Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- 迷宫寻宝(一)(bfs)
迷宫寻宝(一) 时间限制:1000 ms | 内存限制:65535 KB 难度:4 描述 一个叫ACM的寻宝者找到了一个藏宝图,它根据藏宝图找到了一个迷宫,这是一个很特别的迷宫,迷宫里有N个编 ...
- struts2整合json要注意的问题
昨天struts2整合json,一直出错: There is no Action mapped for namespace / and action name ... HTTP Status 404 ...
- AngularJs(三) deployd 服务的使用
使用服务建立数据 在AngularJS(二)中,我搭建好了deployd服务,现在启动服务,创建正在的数据(开始是使用模拟数据),使用cmd命令 一.开启Mongodb数据. 贴图: 二:测试是否正常 ...
- C#中log4net使用方法(一)
Log4net是一个第三方开源组件,它设计的主要目的是组合,生成日志信息,同时将配置保存到各种存储介质或者展现平台中,在实际项目中,Log4net可以保存系统运行情况,可以在系统出现异常时,根据保存的 ...
- 随滚动条滚动的居中div
<!-- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www ...
- 《think in python》学习-6
think in python 有返回函数 我们使用过的内置函数中,有一部分会返回结果,比如 math的 返回值 我们写一个有返回值的函数,计算给定半径的圆的面积,例如这个: def area(rad ...
- SVN报错:can't open file db/txn-current-lock:permission denied 解决方法
其实这个问题是这样的.下面我举个例子:比如版本库SVN是root用户创建的但是启动服务的时候没有选择root启动,而是在其他用户转托管太下启动的,所以只能读不能写. 解决方法:停止svn服务:kill ...
- 修改oracle内存
[oracle@bi11g bin]$ ./sqlplus /nolog SQL*Plus: Release 11.2.0.1.0 Production on Fri Dec 1618:39:36 2 ...
- leetcode Divide Two Integers python
class Solution(object): def divide(self, dividend, divisor): """ :type dividend: int ...