#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. 1.1 Java 的概述

    [什么是java]:Java是一种可以撰写跨平台应用软件的面向对象的程序设计语言,是有SunMicrosystems公司于1995年5月推出的Java程序设计语言和Java平台(即JavaSE,Jav ...

  2. Eclipse生成部署描述符(web.xml)

    右键点击你的web项目名--->Java EE Tools-->Generate Deployment  Descriptor Stub 要想自动生成,只需在创建web项目时,把最后一页的 ...

  3. [Robot Framework] 怎么做数学运算?

    运用BuiltIn里面的Set Variable

  4. OneZero第三周第五次站立会议(2016.4.8)

    1. 时间: 15:10--15:25  共计15分钟. 2. 成员: X 夏一鸣 * 组长 (博客:http://www.cnblogs.com/xiaym896/), G 郭又铭 (博客:http ...

  5. 使用 IntelliTrace 调试应用程序

    IntelliTrace 如何能够大幅改善您的日常开发活动,并提升您快速轻松诊断问题的能力,而不必重新启动应用程序和使用传统的“中断-单步执行-检查”技术进行调试.介绍了组织如何能够通过在测试过程中收 ...

  6. [C#.net]处理UTF-8文件乱码

    今天帮同事处理一个2M左右的文件的格式,发现使用Encoding.default & Encoding.UTF8 & Encoding.GetEncoding("GB2312 ...

  7. MySQL把本地数据库上传到linux

    今天是要导入数据库到linux系统 先用Navicat把sql导出,然后登陆到linux去执行 登陆mysql: mysql -uroot -p123456 创建数据库:create database ...

  8. org.jsoup.HttpStatusException: HTTP error fetching URL. Status=403

    爬取网站的时候 conn = Jsoup.connect(url).timeout(5000).get();直接用get方法,有些网站可以正常爬取. 但是有些网站报403错误,403是一种在网站访问的 ...

  9. php使用include报错require_once(../include.php): failed to open stream: No such file or directo

    引入路径的问题,建议加入include_once $_SERVER['DOCUMENT_ROOT']."/include.php";意思是获取网站根目中的include.php 截 ...

  10. s5-1 CPU调度

    基本概念 通过多道程序设计得到 CPU 的最高利用率 (CPU-- I/O 脉冲周期 - - 进程的执行包括进程在 CPU 上执行和等待 I/O ) 进程的执行以 CPU 脉冲开始,其后跟着 I/O ...