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) {// 我们实现的是在所选行的位置插入一行,因此直接使用了参数indexPathNSArray *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];
}

转载于:https://www.cnblogs.com/Mr-Ygs/p/5630275.html

editActionsForRowAtIndexPath(iOS8) tableview编辑(删除、插入、移动)相关推荐

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

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

  2. ios tableView那些事 (九) tableview的删除

    tableview 的删除一定是很常用的在应用里! 在应用里大多会用到3中删除方式! 第一种滑动方式,在cell 的最右边向右滑动cell ,默认的删除是汉字,我们先改下语言吧!怎么也的改成国语! 这 ...

  3. 【selection】 学习光标API并实现编辑区插入表情图片的功能

    目录 场景介绍 selection介绍 selection API range 介绍 range API 实现编辑区插入表情图片 参考资料 场景介绍 在写web版聊天器时,遇到一个需求: 聊天时用户可 ...

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

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

  5. GridView编辑删除操作

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

  6. IntellijIDEA插件编写-删除/插入/替换文档内容

    错误 ERROR - plication.impl.ApplicationImpl - Assertion failed: Write2018-03-24 01:57:49,835 [ 138880] ...

  7. UITableView (4): 在TableView中移动cell和Section 从TableView中删除cell和section 添加系统默认刷新控件...

    一  .问题:你想用流畅直观的动画来移动和拖拽TableView中的cell和section 方案: 用moveSection:toSection:方法把一个Section移动到新位置. 用moveR ...

  8. 一次开发中并发删除插入死锁分析记录

    这两天在开发一个项目的时候有一个操作是多线程同步数据,每个线程同步一个类型的数据,同步流程是先删除此类型下所有数据,然后批量插入新数据.但是测试过程中会发现有死锁现象,虽然可以直接对删除插入代码使用同 ...

  9. macOS之如何删除插入u盘后会生成的._开头的隐藏文件

    macOS之如何删除插入u盘后会生成的._开头的隐藏文件 概述 删除方法 概述 当你的移动存储设备插入Mac电脑中时,修改里面的文件就会在生成的文件里多增加了一个._开头的隐藏文件,当在window下 ...

最新文章

  1. 高招攻略 领英助你清晰解读大数据专业
  2. 《Groovy极简教程》第12章 Groovy的JSON包
  3. python join字符连接函数的使用方法
  4. vector/list/map/set的插入、删除、遍历 - remove\erase函数
  5. Py之turicreate:turicreate的简介、安装、使用方法之详细攻略
  6. 小朋友嘴里的“金钥匙”,良品小食仙、小鹿蓝蓝们要如何拿到?
  7. 泰克示波器查眼图_泰克示波器
  8. FreeRTOS系列第19篇---FreeRTOS信号量
  9. HTTP协议中GET和POST方法的区别
  10. Node.js与io.js那些事儿
  11. LeetCode(476)——数字的补数(JavaScript)
  12. 为JavaScript日期添加天数
  13. python flask智能租房项目——详情页
  14. 神经网络 BPNN 机器学习 深度学习 拟合 时间序列 预测 分类
  15. 笔记-软考高项-错题笔记汇总4
  16. 如何做公司网站设计,有哪些步骤?
  17. oracle连接失败的原因总结
  18. python中的in
  19. FMDB数据库的升级
  20. android中Picasso显示网络图片

热门文章

  1. 金融业(互联网金融)创新---我的实地考察和见解
  2. cocos2d-x jni相关目录分析
  3. 终于开通我自己的cnblogs了,自我恭喜下··
  4. getContentPane()到底是什么?
  5. 浅谈iPhone和iPad开发中的图标设置
  6. openssl工具调试ssl加密ftp
  7. ubuntu14.04 访问windows目录的方法 mount.cifs方式 取代smbfs方式
  8. u-boot移植第五弹——2013.10u-boot通过tftp下载到内存中运行
  9. c语言解决一元二次方程,一元二次方程求解程序完整代码
  10. java ref 应用类型_Java中的四种引用类型比较