#import "ViewController.h"
#import "Swift_OC-Swift.h" @interface ViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property(nonatomic,strong)NSMutableArray *dataSource; @end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad]; self.dataSource = [NSMutableArray arrayWithObjects:@"1",@"2",@"3",@"4",@"5",nil];
self.tableView.delegate = self;
self.tableView.dataSource = self; // Swift *swift = [[Swift alloc]init];
// //OC调用swift方法("Swift_OC-Swift.h")
// [swift demoFunction];
// //swift调用OC方法(Swift_OC-Bridging-Header)
// [swift swiftFetctionObjectC];
} -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
} -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return self.dataSource.count;
} -(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
if (!cell) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
}
cell.textLabel.text = self.dataSource[indexPath.row];
return cell;
} /////////////////下面实现相关代码////////////////////////////
-(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath{
return YES;
} //返回IOS8之前只能返回一个按钮
//- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
//{
// return UITableViewCellEditingStyleDelete;
//}
//
//-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{
//
// if (editingStyle ==UITableViewCellEditingStyleDelete) {
// [self.dataSource removeObjectAtIndex:indexPath.row];
// [self.tableView deleteRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationAutomatic];
// }
//} //IOS8以后可以返回多个按钮
- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath{ //设置删除按钮
UITableViewRowAction *deleteRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"删除" handler:^(UITableViewRowAction *action,NSIndexPath *indexPath) {
[self.dataSource removeObjectAtIndex:indexPath.row];
[self.tableView deleteRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationAutomatic];
}]; //设置收藏按钮
UITableViewRowAction *collectRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"收藏" handler:^(UITableViewRowAction *action,NSIndexPath *indexPath) {
NSLog(@"收藏了");
}]; //设置置顶按钮
UITableViewRowAction *topRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"置顶" handler:^(UITableViewRowAction *action,NSIndexPath *indexPath) {
[self.dataSource exchangeObjectAtIndex:indexPath.row withObjectAtIndex:0];
NSIndexPath *firstIndexPath = [NSIndexPath indexPathForRow:0 inSection:indexPath.section];
[tableView moveRowAtIndexPath:indexPath toIndexPath:firstIndexPath];
}]; //设置置顶按钮
UITableViewRowAction *testRowAction1 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"测试1" handler:^(UITableViewRowAction *action,NSIndexPath *indexPath) {
NSLog(@"测试1");
}];
UITableViewRowAction *testRowAction2 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"测试2" handler:^(UITableViewRowAction *action,NSIndexPath *indexPath) {
NSLog(@"测试2");
}];
UITableViewRowAction *testRowAction3 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"测试2" handler:^(UITableViewRowAction *action,NSIndexPath *indexPath) {
NSLog(@"测试3");
}];
collectRowAction.backgroundEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
topRowAction.backgroundColor = [UIColor blueColor];
collectRowAction.backgroundColor = [UIColor grayColor]; //经测试可以返回无限个....
return @[deleteRowAction,collectRowAction,topRowAction,testRowAction1,testRowAction2,testRowAction3];
}

效果图:

iOS cell左滑出现多个功能按钮(IOS8以后支持)的更多相关文章

  1. ios cell左滑删除

    iOS项目开发小技能 (三) -UITableView实现Cell左划删除等自定义功能 www.MyException.Cn  网友分享于:2015-06-05  浏览:0次   iOS项目开发小技巧 ...

  2. iOS UITableView左滑操作功能的实现(iOS8-11)

    WeTest 导读 本文主要是介绍下iOS 11系统及iOS 11之前的系统在实现左滑操作功能上的区别,及如何自定义左滑的标题颜色.字体大小. 一.左滑操作功能实现 1.如果左滑的时候只有一个操作按钮 ...

  3. 高仿微信实现左滑显示删除button功能

    在实际项目中删除列表中的某一项是很常见的功能.传统的做法能够使用长按监听器等,而如今流行的做法是左滑弹出删除button,微信,QQ等都是这么做的,以下做一个演示样例,代码例如以下: 主页面MainA ...

  4. UITableView设置Cell左滑多个按钮(编辑,删除,置顶等)

    一.iOS7不支持cell多个按钮这个时候可以使用一个三方库JZTableViewRowAction,引用类扩展文件并实现其代理方法 JZTableViewRowAction下载地址:http://d ...

  5. 第八篇、UITableView常用功能(左滑出现多个按钮,多选删除等)

    1.左滑动出现多个按钮 /** * 只要实现了这个方法,左滑出现按钮的功能就有了 (一旦左滑出现了N个按钮,tableView就进入了编辑模式, tableView.editing = YES) */ ...

  6. cell上的按钮点击和左滑冲突

    cell上的某个按钮的点击事件,当cell左滑的时候,只要活动的区域也在按钮上,那么按钮的点击事件也会调用. fix: 给按钮添加一个手势(TapGesture)那么当点击的时候就会响应点击手势的方法 ...

  7. tableview左滑按钮 tableviewcell自定义左滑按钮

    当我们在使用tableview时,往往需要在cell左滑时显示一个或是多个按钮,但系统默认的只可显示一个,如常见的删除按钮,那么当我们的需求要求要有多个按钮时又该怎么办呢,我们往下看. 首先,现看看系 ...

  8. UITableViewCell左滑的时候添加多个按钮的方法(iOS8+)以及UIRefreshControl(iOS6+)的使用。

    之前想在cell左滑的时候添加更多的按钮而不是只有‘删除’按钮如下所示,貌似不是一件简单的事.但是现在只要实现几个方法就行了. 代码写的比较垃圾,重在理解这个知识.. . 具体代码: // //  T ...

  9. 使用zepto实现QQ消息左滑删除效果

    有这样一个需求: 1. 有一个列表,将每一个列表项左滑动出现删除按钮: 2. 右滑动隐藏删除按钮: 3. 点击这个删除按钮删除该列表项. 完成以后的效果: 这是微信网页端的页面,使用的是 zepto ...

随机推荐

  1. java.lang.NoClassDefFoundError: org/apache/ibatis/cursor/Cursor

    因为mybatis的版本和mybatis-spring的版本不兼容导致的,解决方法:mybatis的3.4.0及以上版本用mybatis-spring1.3.0及以上版本:mybatis的3.4.0以 ...

  2. 1.2 Java中的注释

    Eclipse中的快捷键  单行注释   Ctrl+/ 多行注释    Ctrl+Shift+/  文档注释    Shift +Alt+j /** * @author Lenovo * 文档注释 * ...

  3. C++连接MySQL(Windows)

    一般来说,VS下采用微软自身的SQL Server是比较常见的做法,但SQL Server只适合学习,不适合真正应用.在此,我们选择MySQL作为后台数据库.C++语言本身并没有提供访问数据库的东西, ...

  4. 看懂 Fiddler 的瀑布图

    最近准备给组内的新同学们分享下 Fiddler 这枚神器,可以讲的地方太多,我打算把一节课讲不完的内容写在博客上,大家可以随便看看.今天先介绍下 Fiddler 的瀑布图. 每个网络请求都会经历域名解 ...

  5. UI设计教程分享:关于海报的合成过程

    一张好的产品创意合成海报,能瞬间提升商品价值感,同时场景和相关元素的融入,让消费者瞬间明白商品属性及内涵.同时为商品营造的使用场景拥有更强的代入感,从而刺激转化.好的创意合成海报能为消费者带来视觉冲击 ...

  6. SQL注入漏洞总结

    目录: 一.SQL注入漏洞介绍 二.修复建议 三.通用姿势 四.具体实例 五.各种绕过 一.SQL注入漏洞介绍: SQL注入攻击包括通过输入数据从客户端插入或“注入”SQL查询到应用程序.一个成功的S ...

  7. Map 概述

    map定义:将键映射到值的对象.key必须唯一,但是value可以重复.当你添加相同key的值的时候,value会被覆盖. 与之前的collection有什么区别呢? A:Map 存储的是键值对形式的 ...

  8. m序列生成电路

    m序列

  9. 尝试解决nginx的499错误1

  10. python递归和二分法

    一.递归 1.递归就是自己调用自己 def fn(n): print(n) fn(n+1) fn(1) #递归深度官方1000 一般都递归到998 2.树形结构的遍历 import os def fn ...