iOS tableView右滑显示选择
如何使用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==){
- // 添加一个删除按钮
- deleteRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"删除" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
- NSLog(@"点击了删除");
- }];
- }
- else if (indexPath.row==){
- // 添加一个删除按钮
- 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==){
- // 添加一个删除按钮
- 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==) {
- return @[deleteRowAction];
- }else if (indexPath.row==){
- return @[deleteRowAction,moreRowAction];
- }else if(indexPath.row==){
- return @[deleteRowAction,moreRowAction,sanRowAction];
- }else if(indexPath.row==){
- return @[deleteRowAction,moreRowAction,sanRowAction,OK];
- }
- return nil;
- }
iOS tableView右滑显示选择的更多相关文章
- iOS系统右滑返回全局控制方案
前言 今天有个小需求,在点击导航条上的返回按钮之前要调用某个API,并弹出UIAlertView来显示,根据用户的选项判断是否是返回还是继续留在当前控制器.举个简单的例子,当点击导航条上的左上角返回按 ...
- iOS 开发 右滑返回上一级控制器
#import <objc/runtime.h> @interface UINavigationController (Transition)<UIGestureRecognizer ...
- iOS页面右滑返回的实现方法总结
1.边缘触发的系统方法 ①系统返回按钮 self.navigationController.interactivePopGestureRecognizer.enabled = YES; ②自定义返回 ...
- tabelView右滑选择进行删除
如何使用UITableViewRowAction实现右滑选择呢? 1.在iOS8以前,我们实现tableview中滑动显示删除,置顶,更多等等的按钮时,都需要自己去实现,在iOS8中系统已经写好了,只 ...
- iOS开发之自定义导航栏返回按钮右滑返回手势失效的解决
我相信针对每一个iOS开发者来说~除了根视图控制器外~所有的界面通过导航栏push过去的界面都是可以通过右滑来返回上一个界面~其实~在很多应用和APP中~用户已经习惯了这个功能~然而~作为开发者的我们 ...
- iOS开发之--单个页面禁止右滑返回操作
禁止右滑: if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) ...
- iOS 当使用FD_FullscreenPopViewController的时候遇到scrollView右滑手势无法使用的解决
当我们在ViewController中有scrollView的时候, 可能会遇到右滑无法响应返回手势, 有以下解决办法: 自定义scrollView, 实现该scrollView的以下方法即可: @i ...
- Cell右滑 多个编辑选项栏
简单粗暴,一看就能明白 关于右滑cell,能滑出来两个以上的选项栏,可以如下这么做,但是要注意下面的注意事项,就是关于iOS8前后的问题,注释写的很清楚了.可以直接复制到自己的代码里看的会更明白. / ...
- Cell右滑的动作状态
//允许cell可以进行编辑 - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)index ...
随机推荐
- Sql Server系列:Select基本语句
1 T-SQL中SELECT语法结构 <SELECT statement> ::= [WITH <common_table_expression> [,...n]] <q ...
- MVC4做网站后台:栏目管理1、添加栏目
把栏目添加删除跟前台混在一起结构清晰,现在有了后台管理的区域就把后台管理相关的代码分开. 要实现功能: 1.添加栏目 2.删除栏目 3.修改栏目信息 -- 一.开始 1.添加 接口InterfaceC ...
- jsp通过易宝方式实现在线支付
项目下载地址: https://github.com/hjzgg/OnlinePayment 参考:http://blog.csdn.net/jadyer/article/details/738025 ...
- 详解 ML2 Core Plugin(I) - 每天5分钟玩转 OpenStack(71)
我们在 Neutron Server 小节学习到 Core Plugin,其功能是维护数据库中 network, subnet 和 port 的状态,并负责调用相应的 agent 在 network ...
- Android自定义View 画弧形,文字,并增加动画效果
一个简单的Android自定义View的demo,画弧形,文字,开启一个多线程更新ui界面,在子线程更新ui是不允许的,但是View提供了方法,让我们来了解下吧. 1.封装一个抽象的View类 B ...
- ZOJ Problem Set - 1240 IBM Minus One
水题不解释,就是注意下格式,没输出一行字符串记得加一个空白行 #include <stdio.h> #include <string.h> int main() { ; ]; ...
- 解读SDN的东西、南北向接口
北向接口(Northbound Interface)是为厂家或运营商进行接入和管理网络的接口,即向上提供的接口. 南向接口(Southbound Interface)是提供对其他厂家网元的管理功能,支 ...
- JavaScript的三种工业化调试方法
JavaScript的三种工业化玩法 软件工程中任何的语言如果想要写出健壮的代码都需要锋利的工具,当然JavaScript也不例外,很多朋友刚入门的时候往往因为工具选的不对而事半功倍,JavaScri ...
- [Asp.net 5] Logging-新日志系统目录
楼主有个美好的愿望——把asp.net 5所有能看懂的代码一一呈现给大家(比如C++,楼主就看不懂).现在已经做完了依赖注入.多语言.配置文件三部分,比较基础的日志就成为了楼主的下一个目标.下面是楼主 ...
- C#获得MAC地址(网卡序列号)代码
代码如下: //获得网卡序列号 //MAc地址 http://www.cnblogs.com/sosoft/ public string GetMoAddress() { string MoAddre ...