zoukankan      html  css  js  c++  java
  • UITableView-批量操作

    • 点击编辑按钮进入编辑模式
      // 进入编辑模式
      [self.tableView setEditing:!self.tableView.isEditing animated:YES];
      // 允许在编辑模式进行多选操作
      self.tableView.allowsMultipleSelectionDuringEditing = YES;
    • UITableView的代理方法

      /**
        * 只要实现这个方法,左划cell出现删除按钮的功能就有了
        * 用户提交了添加(点击了添加按钮)删除(点击了删除按钮)操作时会调用
        */
        - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
        {
            if (editingStyle == UITableViewCellEditingStyleDelete) {  // 点击了“删除”
                // 删除模型
                [self.deals removeObjectAtIndex:indexPath.row];
      
                // 刷新表格
        //        [self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationLeft];
                [self.tableView reloadData];
            } else if (editingStyle == UITableViewCellEditingStyleInsert) { // 点击了+
                NSLog(@"+++++ %zd", indexPath.row);
            }
        }
        /**
        * 这个方法决定了编辑模式时,每一行的编辑类型:insert(+按钮)、delete(-按钮)
         */
        - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
        {
            return indexPath.row % 2 == 0? UITableViewCellEditingStyleInsert:     UITableViewCellEditingStyleDelete;
        }

      这个方法可以设置左滑功能的样式

        - (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath{
            UITableViewRowAction *action = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"增加" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
            // 点击增加的时候调用
            NSLog(@"增加");
      
        }];
        action.backgroundColor = [UIColor greenColor];
      
        UITableViewRowAction *action1 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"删除" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
            // 点击删除的时候调用
            NSLog(@"删除");
        }];
        return @[action,action1];
      }

  • 相关阅读:
    P1629 邮递员送信
    P1119 灾后重建
    最短路问题
    P1194 买礼物
    最小生成树
    P1038 神经网络
    P2661 信息传递
    mysql 5.7启动报错
    docker flannel网络部署和路由走向分析
    k8s---无头服务
  • 原文地址:https://www.cnblogs.com/luoze/p/5467931.html
Copyright © 2011-2022 走看看