tabelView右滑选择进行删除
如何使用UITableViewRowAction实现右滑选择呢?
1、在iOS8以前,我们实现tableview中滑动显示删除,置顶,更多等等的按钮时,都需要自己去实现,在iOS8中系统已经写好了,只要一个代理方法和一个类就行了
2、iOS8的协议对了一个方法,返回值是数组的tableview:editActionForRowAtIndexPath:方法,我们可以在方法内部写好几个按钮,然后放到数组中返回,那些按钮的类就是UITableviewRowAction
3、在UITableviewRowAction类。我们可以设置按钮的样式,显示文字、背景色和按钮事件(在block内实现)
4、在代理方法中,我们可以常见多个按钮放到数组中返回,最先放入数组的按钮显示在最右边,最后放入的显示在最左边
5、如果自己设定一个或多个按钮,系统自带的删除按钮就消失了
设置tableView可以编辑
- (BOOL)tableView: (UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath
{
return YES;
}
UITableViewRowAction的使用方法:
+ (instancetype)rowActionWithStyle:(UITableViewRowActionStyle)style title:(nullable NSString *)title handler:(void (^)(UITableViewRowAction *action, NSIndexPath *indexPath))handler;
重写UITableViewDelegate的
- (nullable NSArray<UITableViewRowAction *> *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath
方法。

- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath
{ if(indexPath.row==0){
// 添加一个删除按钮
deleteRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"删除" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
NSLog(@"点击了删除"); }]; }
else if (indexPath.row==1){
// 添加一个删除按钮
deleteRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"删除" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
NSLog(@"点击了删除"); }]; // 添加一个修改按钮
moreRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"修改" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
NSLog(@"点击了修改");
}];
moreRowAction.backgroundEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark]; }
else if (indexPath.row==2){
// 添加一个删除按钮
deleteRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"删除" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
NSLog(@"点击了删除"); }]; // 添加一个修改按钮
moreRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"修改" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
NSLog(@"点击了修改");
}];
moreRowAction.backgroundEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark]; // 添加一个发送按钮 sanRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"发送" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
NSLog(@"点击了发送");
}];
sanRowAction.backgroundColor=[UIColor orangeColor]; }
else{
// 添加一个删除按钮
deleteRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"删除" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
NSLog(@"点击了删除"); }]; // 添加一个修改按钮
moreRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"修改" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
NSLog(@"点击了修改");
}];
moreRowAction.backgroundEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark]; // 添加一个发送按钮 sanRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"发送" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
NSLog(@"点击了发送");
}];
sanRowAction.backgroundColor=[UIColor orangeColor];
// 添加一个发送按钮 OK = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"OK键" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
NSLog(@"点击了OK");
}];
OK.backgroundColor=[UIColor purpleColor]; } // 将设置好的按钮放到数组中返回
if (indexPath.row==0) {
return @[deleteRowAction]; }else if (indexPath.row==1){
return @[deleteRowAction,moreRowAction]; }else if(indexPath.row==2){
return @[deleteRowAction,moreRowAction,sanRowAction]; }else if(indexPath.row==3){
return @[deleteRowAction,moreRowAction,sanRowAction,OK]; }
return nil;
}
tabelView右滑选择进行删除的更多相关文章
- iOS tableView右滑显示选择
如何使用UITableViewRowAction实现右滑选择呢? 1.在iOS8以前,我们实现tableview中滑动显示删除,置顶,更多等等的按钮时,都需要自己去实现,在iOS8中系统已经写好了,只 ...
- Android SwipeToDismiss:左滑/右滑删除ListView条目Item
<Android SwipeToDismiss:左右滑动删除ListView条目Item> Android的SwipeToDismiss是github上一个第三方开源框架(githu ...
- Android滑动列表(拖拽,左滑删除,右滑完成)功能实现(1)
场景: 近期做的TODO APP需要在主页添加一个功能,就是可以左滑删除,右滑完成.看了一下当前其他人做的例如仿探探式的效果,核心功能基本一样,但是和我预想的还是有少量区别,于是干脆自己重头学一遍如何 ...
- jquery左划出现删除按钮,右滑隐藏
jquery左侧划出显示删除按钮,右滑动隐藏删除按钮 <!doctype html> <html> <head> <meta charset="ut ...
- Cell右滑 多个编辑选项栏
简单粗暴,一看就能明白 关于右滑cell,能滑出来两个以上的选项栏,可以如下这么做,但是要注意下面的注意事项,就是关于iOS8前后的问题,注释写的很清楚了.可以直接复制到自己的代码里看的会更明白. / ...
- App开发流程之右滑返回手势功能续
上一篇记录了利用系统私有变量和方法实现右滑返回手势功能:http://www.cnblogs.com/ALongWay/p/5893515.html 这篇继续记录另一种方案:利用UINavigatio ...
- Cell右滑的动作状态
//允许cell可以进行编辑 - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)index ...
- navagationController 的子控制器如何取消右滑返回
1.首先在navagationController的某个控制器中 遵守:UIGestureRecognizerDelegate 2.在viewDidload中设置: self.navigationCo ...
- 截获导航控制器系统返回按钮的点击pop及右滑pop事件
前几天看了@栾小布的一篇文章:Custom backBarButtonItem,在跟着做的时候我又顺便扩展了一些,写此文章的目的是为了总结一下自己所写的东西,方便以后翻看容易,同时也是自己入行iOS一 ...
随机推荐
- iOS架构师之路:控制器(View Controller)瘦身设计
前言 古老的MVC架构是容易被iOS开发者理解和接受的设计模式,但是由于iOS开发的项目功能越来越负责庞大,项目代码也随之不断壮大,MVC的模糊定义导致我们的业务开发工程师很容易把大量的代码写到视图控 ...
- IIS下注册COM组件(转)
以Excel为例 问题描述: 检索 COM 类工厂中 CLSID 为 {00024500-0000-0000-C000-000000000046}的组件时失败,原因是出现以下错误: 80070005基 ...
- The Pragmatic Programmer Quick Reference Guide
1.关心你的技艺 Care About Your Craft 如果不在乎能否漂亮地开发出软件,你又为何要耗费生命去开发软件呢? 2.思考!你的工作 Think! About Your Work 关掉自 ...
- Liunx的各种小指令
tsshutdown -y ----关闭所有服务tsboot -g COMMON ----启动公共服务tsboot -g ETXX ----启动XX服务 tsma -e oet1 -l 172.X ...
- Android侧滑菜单代码实现
前两天学习了hyman老师讲的Android侧滑菜单的实现,经过自己的整理分享出来给大家学习一下 现在很多APP都有菜单侧滑的功能,本篇文章主要讲解使用自定义的HorizontalScrollView ...
- FTP : mput with no confirmation
When you are transferring multiple files to your destination, 'mput' or 'mget' will be the one comma ...
- SQL注入的常用函数和语句
1.系统函数 version() Mysql版本user() 数据库用户名database() 数据库名@@datadir 数据库路径@@version_compile_os 操 ...
- CSS样式-文字超出宽部分用省略号代替
.name {text-overflow: ellipsis;white-space: nowrap;overflow: hidden;display:block;width:120px; }
- 黑马----面向方面编程AOP
黑马程序员:Java培训.Android培训.iOS培训..Net培训 JAVA反射-面向方面编程AOP 一.面向方面的需求 有如下模型: 需要统计客户登录时间.使用系统情况,或系统运行日记等信息时, ...
- 开篇----JavaScript细节的那些事儿
JavaScript现在已经是全世界浏览器通用的语言,目前也完全可以在服务器端做开发,如Node.js,市面上好的JavaScript的书有很多,有的还是经典之作,值得收藏. 趁此东风,打算接下来写一 ...