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];

    }

  • 相关阅读:
    Nbear实体和接口 CodeSmith模版
    prototype1.4版中文参考手册(word,pdf,chm)
    SharePoint 2013 (SharePoint 15)的新特性
    没有域环境下安装SharePoint 2010
    产品经理(PM)常用原型图设计工具
    【转贴】mysql导入数据load data infile用法
    重新学javaweb!
    关于HIbernate中的lazy属性的一些解释
    JAVA程序员基本测试题目
    添加sql server约束
  • 原文地址:https://www.cnblogs.com/liuzhenjie/p/5451255.html
Copyright © 2011-2022 走看看