zoukankan      html  css  js  c++  java
  • Cell右滑 多个编辑选项栏

    简单粗暴,一看就能明白
    关于右滑cell,能滑出来两个以上的选项栏,可以如下这么做,但是要注意下面的注意事项,就是关于iOS8前后的问题,注释写的很清楚了。可以直接复制到自己的代码里看的会更明白。

     1 //允许cell可以进行编辑
     2 - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath{
     3     return YES;
     4 }
     5 //cell的编辑类型
     6 - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
     7 {
     8     return UITableViewCellEditingStyleDelete;
     9 }
    10 //可以不调用这个代理 默认是 Delete    编辑右滑出的title
    11 - (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath
    12 {
    13     return @"删除";
    14 }
    15 //iOS8 以前  只有一个删除选项
    16 - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
    17 {
    18     NSLog(@"点击了删除");
    19     
    20 }
    21 //iOS 8  以后 可以右滑出多个选项栏 就用这个代理方法,
    22 - (nullable NSArray<UITableViewRowAction *> *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath NS_AVAILABLE_IOS(8_0) __TVOS_PROHIBITED
    23 {
    24     UITableViewRowAction *delete = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"删除" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
    25         NSLog(@"点击了删除");
    26     }];
    27     
    28     UITableViewRowAction *editing = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"编辑" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
    29         NSLog(@"点击了编辑");
    30     }];
    31     editing.backgroundColor = [UIColor Theme_Color];
    32     
    33     //加入数组的第一个为最右边的第一个 (可以添加多个)
    34     return @[delete,editing];
    35 }
  • 相关阅读:
    换种方式思考问题
    win7 下的open live writer代码插件
    vue-todolist
    vue-新建项目出错情况分析
    vue新建项目
    AJAX(一、基本知识)
    2016年度工作总结
    常看常遇见之一——BS架构VS CS架构
    thinkjs——session
    关于Listener
  • 原文地址:https://www.cnblogs.com/crazygeek/p/5720216.html
Copyright © 2011-2022 走看看