美文网首页
uitableview增加多个左滑选项

uitableview增加多个左滑选项

作者: 小玉de简书 | 来源:发表于2017-05-27 16:57 被阅读66次

    今天看我们的项目里有一个用第三方增加多个左滑选项的,他们说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 

    相关文章

      网友评论

          本文标题:uitableview增加多个左滑选项

          本文链接:https://www.haomeiwen.com/subject/bueqfxtx.html