editActionsForRowAtIndexPath(iOS8) tableview编辑(删除、插入、移动)
ios8 出来的左滑小菜单 可以自定义想要的按钮 (要求ios8以上)
- (nullable NSArray<UITableViewRowAction *> *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewRowAction *deleteAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"删除" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
NSLog(@"-----------=点击删除");
}];
UITableViewRowAction *editAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"编辑" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
NSLog(@"-----------=点击编辑");
}];
UITableViewRowAction *topAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"置顶" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
NSLog(@"-----------=点击置顶");
}];
UITableViewRowAction *signAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"标记未读" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
NSLog(@"-----------=标记");
}];
// 毛玻璃效果
deleteAction.backgroundEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
editAction.backgroundColor = [UIColor blueColor];
topAction.backgroundColor = [UIColor grayColor];
signAction.backgroundColor = [UIColor yellowColor];
return @[deleteAction, editAction, topAction, signAction];
}
可以在导航栏右边放编辑按钮,删除操作
-(void)delete:(UIBarButtonItem *)sender {
if (self.tableView.editing == NO) {
self.tableView.editing = YES;
sender.title = @"完成";
}else if (self.tableView.editing == YES) {
self.tableView.editing = NO;
sender.title = @"编辑";
}
}
// 设置tableView是否可以编辑
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath{
return YES;
}
// 设置删除操作时候的标题
-(NSString*)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath {
return @"删除";
}
// 编辑模式
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
return UITableViewCellEditingStyleDelete;
}
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{
if (editingStyle == UITableViewCellEditingStyleDelete) {
[self.arrayM removeObjectAtIndex:indexPath.row];
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationNone];
}
}
导航栏右边放编辑按钮,插入操作
// 设置tableView是否可以编辑
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath{
return YES;
} - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
return UITableViewCellEditingStyleInsert;
} -(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{ if (editingStyle == UITableViewCellEditingStyleInsert) { // 我们实现的是在所选行的位置插入一行,因此直接使用了参数indexPath
NSArray *insertIndexPaths = [NSArray arrayWithObjects:indexPath,nil];
// 同样,将数据加到list中,用的row
[self.arrayM insertObject:@"新添加的行" atIndex:indexPath.row];
[tableView insertRowsAtIndexPaths:insertIndexPaths withRowAnimation:UITableViewRowAnimationAutomatic];
}
}
导航栏右边放编辑按钮,移动操作
// 设置编辑模式
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
return UITableViewCellEditingStyleNone;
} // 这个方法用来告诉表格 这一行是否可以移动
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
return YES;
} // 这个方法就是执行移动操作的
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *) sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath { NSUInteger fromRow = [sourceIndexPath row];
NSUInteger toRow = [destinationIndexPath row]; id object = [self.arrayM objectAtIndex:fromRow];
[self.arrayM removeObjectAtIndex:fromRow];
[self.arrayM insertObject:object atIndex:toRow];
}
editActionsForRowAtIndexPath(iOS8) tableview编辑(删除、插入、移动)的更多相关文章
- ListView 分页 排序、编辑、插入和删除
摘自网络地址:http://msdn.microsoft.com/zh-cn/magazine/cc337984.aspx ListView 基础 ListView 是模板驱动的控件,这意味着它默认情 ...
- UITableView 自带编辑删除 自己定义button
一:UITableView 自带编辑删除 1:实现两个方法就可以 #pragma mark tableView自带的编辑功能 -(void)tableView:(UITableView *)tab ...
- tableview 编辑状态设置
#pragma mark - tableview 编辑状态设置 -(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSI ...
- GridView总结二:GridView自带编辑删除更新
GridView自带编辑删除更新逻辑很简单:操作完,重新绑定.总结总结,防止忘记... 效果图: 前台代码: <%@ Page Language="C#" AutoEvent ...
- editplus批量删除重复行(编辑-删除-删除重复行)
editplus快速删除重复数据 多行文本,有些行的文字或数据是重复的,该怎么删除重复部分,只留下不重复的部分?很多人对这个问题感到无比头疼,Editplus同样能快速帮你删除数据. 那么,editp ...
- tableView里删除单元格
tableView里删除单元格 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSInde ...
- GridView编辑删除操作
第一种:使用DataSource数据源中自带的编辑删除方法,这样的不经常使用,在这里就不加说明了. 另外一种:使用GridView的三种事件:GridView1_RowEditing(编辑).Grid ...
- Oracle 序列的创建删除插入
今天学习的是序列的创建蟹盖和删除插入 创建: create Sequence Seq_name increment by n ----序列变化的程度,默认为1,可以为负数表示递减 start ...
- 在线编辑Word——插入图表
在Word中可插入图表,配合使用表格能够更加全方位的展示数据的可信度并增加数据的可读性.本文将通过使用在线编辑器 Spire.Cloud Word 演示如何来插入图表,并设置相关格式化操作.具体步骤如 ...
随机推荐
- CoreCLR源码探索(二) new是什么
前一篇我们看到了CoreCLR中对Object的定义,这一篇我们将会看CoreCLR中对new的定义和处理 new对于.Net程序员们来说同样是耳熟能详的关键词,我们每天都会用到new,然而new究竟 ...
- [新]最近用unity5弄的一些渲染
Unity Separable Bokeh Depth-of-Field Hexagonal Blur Unity3d Realtime Dynamic Clouds Rendering hemisp ...
- NOIP2015 提高组(senior) 解题报告
过了这么久才来发解题报告,蒟蒻实在惭愧 /w\ Day1 T1 [思路] 模拟 [代码] #include<iostream> #include<cstring> #inclu ...
- 坑爹的IE quirk模式【转】
调试一个页面,ie下面页面css样式很是奇怪,各种失效.找了半天原因不知道怎么回事.最后在调试工具中发现,文档模式为quirk,改成别的(IE 7|8|9)正常. 为什么会自动选择此文档模式呢? 先看 ...
- 在Windows8工作站上安装可靠多播协议
为什么要安装可靠多播协议? 答:随着因特网的发展,出现了视频点播.电视会议.远程学习.计算机协同工作等新业务.传统的点到点通信方式,不仅浪费大量的网络带宽,而且效率很低.一种有效利用现有带宽的技术 ...
- javascript中的function对象
function对象都是Function的实例: > Object.getOwnPropertyNames(Function) [ 'length', 'name', 'arguments', ...
- sql server smo
在SQL Server2005以前的版本中,SQL分布式管理对象(SQL-DMO)为我们提供了非常有效的方法来通过编程的方式管理SQL Server.SQL-DMO支持基于COM的接口,开发人员可以通 ...
- 让BOOTSTRAP默认SLIDER支持触屏设备
var isTouch=('ontouchstart' in window); if(isTouch){ $(".carousel").on('touchstart', funct ...
- CSS- 兼容样式记录
前面加* 或者_,不是CSS的正常写法,而是利用IE的解析BUG,从而实现所需要的效果.应尽量避免使用吧.* margin-left:32px; /*所有浏览器*/*margin-left:32px; ...
- linux 查看并终止进程
1,查看port被那个进程占用 比如: netstat -anp | grep 1160 ps:查看port1169被那个进程占用. 2.查找进程 比如 :ps -ef | grep 'tomcat' ...