uitableview增加多个左滑选项

今天看我们的项目里有一个用第三方增加多个左滑选项的,他们说UITableView  实现不了,我不信,然后我就去百度了。

后来发现百度倒是提到一个8.0以后UITableView增加的api

- (nullable NSArray*)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath

一句话带过,也没有说具体方法,然后我再搜出了第三方就没有别的了,然后我就自己在UITableView 的代理方法里总结研究。

效果图

使用方法如下:

- (nullable NSArray*)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath

{

NSMutableArray *arrbtn = [[NSMutableArray alloc] init];

NSArray *title = @[@"delect",@"show",@"update"];

NSArray *color = @[[UIColor redColor],[UIColor grayColor],[UIColor greenColor]];

for (int a = 0; a <3; a++) {

UITableViewRowAction *action = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:title[a] handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {

if (a == 0) {

[self tableView:tableView changeSelectStyle:UITableViewLeftSelectStyleDelect indexPath:indexPath];

}else if (a == 1)

{

[self tableView:tableView changeSelectStyle:UITableViewLeftSelectStyleShow indexPath:indexPath];

}

else if (a ==2)

[self tableView:tableView changeSelectStyle:UITableViewLeftSelectStyleUpdate indexPath:indexPath];

}];

action.backgroundColor = color[a];

[arrbtn addObject:action];

}

return  (NSArray *)arrbtn;

}

这就完成了创建,生成,返回点击的效果,比第三方简单多了,我看到在qq上使用的就是这种方法。

如果大家还不知道怎么写可以参考下demo:多个左滑选项的demo

cocoachina下载路径:http://code.cocoachina.com/view/135182 

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • #pragma mark someValueAboutTableView 1.tableView的样式:UITab...
    潇岩阅读 952评论 0 0
  • 1.nav1.navigationBar.barStyle=UIBarStyleBlack; //改变导航栏背景颜...
    SadMine阅读 1,616评论 1 4
  • 自定义单元格 表格无论有多少中自定义单元格样式 每一种自定义单元格都有复用的能力所以每一个单元格都要带有一个静态局...
    DVWang阅读 277评论 0 0
  • 概述在iOS开发中UITableView可以说是使用最广泛的控件,我们平时使用的软件中到处都可以看到它的影子,类似...
    liudhkk阅读 9,086评论 3 38
  • 版权声明:未经本人允许,禁止转载. 1. TableView初始化 1.UITableView有两种风格:UITa...
    萧雪痕阅读 2,918评论 2 10