zoukankan      html  css  js  c++  java
  • 批量删除

    - (void)viewDidLoad {

        [super viewDidLoad];

    //    self.tableView.allowsMultipleSelection = YES;

        

        // 告诉tableView在编辑模式下可以多选

        self.tableView.allowsMultipleSelectionDuringEditing = YES;

        

        self.deletedButton.hidden = YES;

    }

     

    #pragma mark - 按钮的点击

    - (IBAction)MultipleRemove {

        // 进入编辑模式

        [self.tableView setEditing:!self.tableView.isEditing animated:YES];

        self.deletedButton.hidden = !self.tableView.isEditing;

    }

     

    - (IBAction)remove {

        // 千万不要一边遍历一边删除,因为每删除一个元素,其他元素的索引可能会发生变化

        NSMutableArray *deletedWine = [NSMutableArray array];

        for (NSIndexPath *indexPath in self.tableView.indexPathsForSelectedRows) {

            [deletedWine addObject:self.wineArray[indexPath.row]];

        }

        

        // 修改模型

        [self.wineArray removeObjectsInArray:deletedWine];

        

        // 刷新表格

    //    [self.tableView reloadData];

        [self.tableView deleteRowsAtIndexPaths:self.tableView.indexPathsForSelectedRows withRowAnimation:UITableViewRowAnimationAutomatic];

    }

     ---------------------------

     // 获取要删除的酒模型

        NSMutableArray *deletedWine = [NSMutableArray array];

        for (NSIndexPath *indexPath in self.seletedIndexPath) {

            [deletedWine addObject:self.wineArray[indexPath.row]];

        }

        

        // 删除模型

        [self.wineArray removeObjectsInArray:deletedWine];

        

        // 刷新表格

        [self.tableView deleteRowsAtIndexPaths:self.seletedIndexPath withRowAnimation:UITableViewRowAnimationAutomatic];

        // 清空数组

        [self.seletedIndexPath removeAllObjects];

     

     

     

     

    #pragma mark - UITableViewDelegate

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

    {

        // 修改模型

        LZJWine *wine = self.wineArray[indexPath.row];

        if (wine.isCheched) { // 之前是打钩的,取消打钩

            wine.checked = NO;

            [self.seletedIndexPath removeObject:indexPath];

        } else { // 之前不是打钩的,现在打钩

            wine.checked = YES;

            [self.seletedIndexPath addObject:indexPath];

        }

        

        // 刷新表格

        [self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];

    }

  • 相关阅读:
    重定向是否可以重定向到post接口
    ForkJoin(工作窃取)初步使用,计算偶数集合
    Dubbo服务的三种发布模式
    mysql开启慢查询日志
    Hashmap的结构,1.7和1.8有哪些区别
    idea回滚已经push的代码
    rabbitmq集群安装配置
    restful好处,表单提交put/delete
    BIO/NIO/AIO待完成
    判断一个对象是否可以被回收
  • 原文地址:https://www.cnblogs.com/liuzhenjie/p/5451255.html
Copyright © 2011-2022 走看看