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编辑(删除、插入、移动)的更多相关文章

  1. ListView 分页 排序、编辑、插入和删除

    摘自网络地址:http://msdn.microsoft.com/zh-cn/magazine/cc337984.aspx ListView 基础 ListView 是模板驱动的控件,这意味着它默认情 ...

  2. UITableView 自带编辑删除 自己定义button

    一:UITableView 自带编辑删除 1:实现两个方法就可以 #pragma mark   tableView自带的编辑功能 -(void)tableView:(UITableView *)tab ...

  3. tableview 编辑状态设置

    #pragma mark - tableview 编辑状态设置 -(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSI ...

  4. GridView总结二:GridView自带编辑删除更新

    GridView自带编辑删除更新逻辑很简单:操作完,重新绑定.总结总结,防止忘记... 效果图: 前台代码: <%@ Page Language="C#" AutoEvent ...

  5. editplus批量删除重复行(编辑-删除-删除重复行)

    editplus快速删除重复数据 多行文本,有些行的文字或数据是重复的,该怎么删除重复部分,只留下不重复的部分?很多人对这个问题感到无比头疼,Editplus同样能快速帮你删除数据. 那么,editp ...

  6. tableView里删除单元格

    tableView里删除单元格 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSInde ...

  7. GridView编辑删除操作

    第一种:使用DataSource数据源中自带的编辑删除方法,这样的不经常使用,在这里就不加说明了. 另外一种:使用GridView的三种事件:GridView1_RowEditing(编辑).Grid ...

  8. Oracle 序列的创建删除插入

    今天学习的是序列的创建蟹盖和删除插入 创建: create Sequence Seq_name increment by n     ----序列变化的程度,默认为1,可以为负数表示递减 start ...

  9. 在线编辑Word——插入图表

    在Word中可插入图表,配合使用表格能够更加全方位的展示数据的可信度并增加数据的可读性.本文将通过使用在线编辑器 Spire.Cloud Word 演示如何来插入图表,并设置相关格式化操作.具体步骤如 ...

随机推荐

  1. CoreCLR源码探索(二) new是什么

    前一篇我们看到了CoreCLR中对Object的定义,这一篇我们将会看CoreCLR中对new的定义和处理 new对于.Net程序员们来说同样是耳熟能详的关键词,我们每天都会用到new,然而new究竟 ...

  2. 从html5标准的正式发布到国内CMS的变革

    10月底万维网联盟(W3C)宣布,经过将近8年的艰辛努力,HTML5标准规范终于最终制定完成并正式发布. W3C的正式批准让人们对HTML5更有信心.“这是一个里程碑,标志着很多人员在长达七年时间内投 ...

  3. 2013 ACM区域赛长沙 I LIKE vs CANDLE(ZOJ3734) 很好的一道树形DP

    题意:一棵有根树,每个节点都有一个value值和属性(zan或是 CANDLE).你可以通过反转一些点的属性,反转一个点时候,它的整个子树都会被反转属性.有些点反转消耗代价为X,有些为Y.你的目标的是 ...

  4. Docker系列(五)OVS+Docker网络打通示例

    环境说明 两个虚拟机 操作系统Centos7 DOcker版本1.8 脚本内容: 1  4  7  10  19  27  32    33  39   -j ACCEPT 47    48  # R ...

  5. light oj 1297 Largest Box

    1297 - Largest Box   PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB In t ...

  6. 聊聊LAA(LARGE ADDRESS AWARE)

    博客搬到了fresky.github.io - Dawei XU,请各位看官挪步.最新的一篇是:聊聊LAA(LARGE ADDRESS AWARE).

  7. PHP基本语法(一)

    整形:就是对用整数  正整数与负整数整形的表示:int integer NOTICE:写整形的时候不要在外面再加引号了 浮点:就是小数 3.1415926Float 浮点 布尔值:男和女 真和假 阴和 ...

  8. Filter过滤器(1)

    Filter也称之为过滤器,它是Servlet技术中比较激动人心的技术,WEB开发人员通过Filter技术,对web服务器管理的所有web资源:例如Jsp, Servlet, 静态图片文件或静态 ht ...

  9. &lt;ASP.NET4 从入门到精通&gt;学习笔记3

    第三部分,状态管理与缓存 何为状态管理.起始对于web而言.经过前面章节的解说.已经理解,对于web程序,就是一个无状态的程序.每次的请求与每次的响应,两者之间本身就是独立存在的,这一点对于早期的静态 ...

  10. my.cnf 中字符集设置

    我们的一些业务系统最近出现了一种情况,尤其是新版的ios 设备,在发布消息时,使用了表情符号时,   对gbk 字符集的数据库,写入数据库的数据,在回显时,变成 ‘口口’ 无法回显,   对utf8 ...