zoukankan      html  css  js  c++  java
  • UITableView左滑设置更多的按钮

    /**

     *  代理方法

     *  它可以设置更多的左侧按钮

     *  但是它要覆盖了之前系统的删除按钮

     */

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

    {  //重置删除按钮

        UITableViewRowAction *toTop = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"删除" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {

           // 更新数据

            [self.students removeObjectAtIndex:indexPath.row];

            //更新 tableview

            [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];

            //反馈执行了删除操作

            NSLog(@"删除");

           [tableView setEditing:NO animated:YES];   

        }];

        //设置按钮的背景色

        toTop.backgroundColor =[UIColor redColor];

            //添加一个置顶按钮

        UITableViewRowAction *toTop1 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"置顶" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {

            //刷新数据

            [self.students exchangeObjectAtIndex:indexPath.row withObjectAtIndex:0];

            //把所选项置顶

            NSIndexPath *firstIndexPath = [NSIndexPath indexPathForRow:0 inSection:indexPath.section];

            [tableView moveRowAtIndexPath:indexPath toIndexPath:firstIndexPath];

            //反馈执行了删除操作

            NSLog(@"置顶");

            [tableView setEditing:NO animated:YES];

        }];

        //设置按钮的背景色

        toTop1.backgroundColor =[UIColor grayColor];

     

          //返回我们所设置的按钮,但是得以数组的形式返回;

        return @[toTop,toTop1];

    }

     

  • 相关阅读:
    react setstate
    【css】长文本左侧显示省略号
    react 获取input标签的输入值
    【react 分页器】 基于react-virtualized组件的分页器
    type为number的<input>标签 type和size属性失效
    js 获取Array数组 最大值 最小值
    ubuntu 编辑pdf
    【react redux && flux】
    远程唤醒、WOL、Magic_Packet
    win10无法访问局域网共享文件?(因微软账户和本地账户登陆问题导致)
  • 原文地址:https://www.cnblogs.com/liumu/p/5293669.html
Copyright © 2011-2022 走看看