#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. iOS.Objective-C.Dependency.Graphing-v0.1

    当Project越来越复杂,模块间的依赖就会很复杂,不合理的依赖就出现:不必要的依赖,双向依赖等等. 在iOS Application Project中可以将依赖定义为:对某个头文件的import. ...

  2. C单链表操作

    #include <stdio.h> #include <stdlib.h> #define ElemType int #define Status int #define O ...

  3. 定时任务起的java进程没有释放导致oracle的问题not availavle & out of memory

    最近发现一个问题,我们设置了一个定时任务,用于每天的对账,每天的对账都是启动一个java程序(jar包),时间久了,出现下面的问题: 有很多CardPaymentBatch.jar进程驻留在系统当中, ...

  4. apt install yum失败

    解决办法:sudo apt-get update

  5. Add to Array-Form of Integer LT989

    For a non-negative integer X, the array-form of X is an array of its digits in left to right order.  ...

  6. IOS 小新兵

    2017-07-02 lipo -info BaiduOAuthSDK.a  查看a文件支持的架构 第一个坎: 报错:  未找到模块baiduLogin对应的类BaiduLoginModule.若是自 ...

  7. java 开发微信中回调验证一直提示 解密失败处理(Java)

    微信公众号平台接入JDK6和JDK7及JDK8加解密失败处理(Java) 根据自己jdk版本编译,如jdk7或者jdk6 ,此时部署后提示报错:java.security.InvalidKeyExce ...

  8. java基本例子

    文件结构 D:\jp\jarDemo\IAmMainClass.java import iAmPackage.*; public class IAmMainClass { public static ...

  9. UVA 10405 Longest Common Subsequence

    题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=16&p ...

  10. Alpha 冲刺 (1/10)

    队名 火箭少男100 组长博客 林燊大哥 作业博客 Alpha 冲鸭! 成员冲刺阶段情况 林燊(组长) 过去两天完成了哪些任务 协调各成员之间的工作,对多个目标检测及文字识别模型进行评估.实验,选取较 ...