博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
编辑列表(删除所选项)
阅读量:7162 次
发布时间:2019-06-29

本文共 6628 字,大约阅读时间需要 22 分钟。

hot3.png

效果图如下图所示

注意:编辑页面需要重新新建一个文件,不要想着重用原来的页面

1、下面是编辑页面需要实现的代码 

- (void)viewDidLoad {    [super viewDidLoad];    [self initWithUI];        // Do any additional setup after loading the view from its nib.}- (void)initWithUI {    self.navigationItem.title = QHLocalizedString(@"藏宝记录", nil);        self.editImageView.image = IMAGENAMED(@"capacity_noSele");//capacity_sele    self.chooseReminder.text = QHLocalizedString(@"选择全部", nil);    [self.deleteButton setTitle:QHLocalizedString(@"删除", nil) forState:UIControlStateNormal];        _isDelete = NO;//是否删除成功        //初始化数组中的isSelect=NO;默认不点击    for (QHPiTreasureMyMineListModel *model in _resultArray) {        model.isSelect = NO;    }        [self initWithTableView];    }#pragma mark 初始化TableView- (void)initWithTableView {    self.myTableView.dataSource = self;    self.myTableView.delegate = self;    self.myTableView.tableFooterView = [UIView new];    [self.myTableView registerNib:[UINib nibWithNibName:[QHBuriedTreasureEditTableViewCell identifier] bundle:nil] forCellReuseIdentifier:[QHBuriedTreasureEditTableViewCell identifier]];    self.myTableView.separatorStyle = UITableViewCellSeparatorStyleNone;    }#pragma mark UITableViewDelegate, UITableViewDataSource- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {    return 1;}- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {    return _resultArray.count;}- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {    return 60;}- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {    QHBuriedTreasureEditTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:[QHBuriedTreasureEditTableViewCell identifier]];    cell.model = _resultArray[indexPath.row];        return cell;}- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {    [tableView deselectRowAtIndexPath:indexPath animated:YES];        QHPiTreasureMyMineListModel *model = _resultArray[indexPath.row];    model.isSelect = !model.isSelect;    [_resultArray replaceObjectAtIndex:indexPath.row withObject:model];        NSIndexPath *curIndexPath = [NSIndexPath indexPathForRow:indexPath.row inSection:0];        [self.myTableView reloadRowsAtIndexPaths:@[curIndexPath] withRowAnimation:UITableViewRowAnimationNone];         NSArray *selectArray = [self screenSelectArray:YES];    //如果将列表所有项都进行勾选了,选择全部的按钮也会变亮    if (_resultArray.count == selectArray.count) {        _editImageView.image = IMAGENAMED(@"capacity_sele");        _allSelectBtn.selected = YES;    }else{         _editImageView.image = IMAGENAMED(@"capacity_noSele");        _allSelectBtn.selected = NO;    }    }#pragma mark 根据isSelect进行谓词筛选- (NSArray *)screenSelectArray:(BOOL)isSelect{    NSPredicate *predicate = [NSPredicate predicateWithFormat:[NSString stringWithFormat:@"isSelect == %d",isSelect]];        NSArray *selectArray = [_resultArray filteredArrayUsingPredicate:predicate];    return selectArray;}#pragma mark 选择全部- (IBAction)didChooseAllClicked:(id)sender {    UIButton *btn = sender;    //点击选择全部按钮->全部选择或者全部取消选择    if (btn.selected) {        [_resultArray setValue:@(NO) forKey:@"isSelect"];    }else{        [_resultArray setValue:@(YES) forKey:@"isSelect"];    }        [_myTableView reloadData];        btn.selected = !btn.selected;    if (btn.selected) {         _editImageView.image = IMAGENAMED(@"capacity_sele");    }else{        _editImageView.image = IMAGENAMED(@"capacity_noSele");    }}#pragma mark 删除- (IBAction)didDeleteClicked:(id)sender {      [self showAlertWithTitle:[NSString stringWithFormat:@"%@?", QHLocalizedString(@"确认删除", nil)] message:nil actions:@[QHLocalizedString(@"取消", nil),QHLocalizedString(@"确认", nil)] complete:^(NSInteger selIndex) {        if (selIndex) {            [self deleteList];        }    }];}#pragma mark 删除列表接口- (void)deleteList{    NSArray *idsArray = [[self screenSelectArray:YES] valueForKey:@"treasureId"];    if (idsArray.count == 0) {                [MBProgressHUD showMessag:QHLocalizedString(@"请选择需要删除的记录", nil) toView:self.view afterDelay:hiddenMBPTime];        return;    }        [MBProgressHUD showHUDAddedTo:self.view withTitle:@"" animated:YES];    QHPiBuriedDeleteBatchRequest *deleteApi = [[QHPiBuriedDeleteBatchRequest alloc]init];         NSString *ids = [idsArray componentsJoinedByString:@","];    deleteApi.ids = ids;    [deleteApi startWithCompletionBlockWithSuccess:^(__kindof YTKBaseRequest * _Nonnull request) {        [self objectWithDeleteJson:request.responseJSONObject];    } failure:^(__kindof YTKBaseRequest * _Nonnull request) {        [MBProgressHUD hideAllHUDsForView:self.view animated:YES];    }];}- (void)objectWithDeleteJson:(id)json{     [MBProgressHUD hideAllHUDsForView:self.view animated:YES];    if (QH_VALIDATE_REQUEST(json)) {         [MBProgressHUD showMessag:QHLocalizedString(@"删除成功", nil) toView:self.view afterDelay:hiddenMBPTime];        _isDelete = YES;        [_resultArray removeObjectsInArray:[self screenSelectArray:YES]];        [_myTableView reloadData];            }else{        [MBProgressHUD showMessag:json[@"msg"] toView:self.view afterDelay:hiddenMBPTime];    }}#pragma mark 返回按钮- (void)leftClick:(UIButton *)btn{    [self.navigationController popViewControllerAnimated:YES];    if (_isDelete) {        if (_successBlock) {            _successBlock();        }    }}- (void)deleteSuccess:(void (^)())successBlock{    _successBlock = successBlock;}

2、未编辑页面的跳转

#pragma mark 编辑- (void)rightClick:(UIButton *)btn {    [_screenArray removeAllObjects];//因为是订单,所以未支付的情况下不能删除,所以需要根据paystate==2进行谓词筛选已经进行支付的订单    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"paystate CONTAINS '2'"];        [_screenArray addObjectsFromArray:[_dataArray filteredArrayUsingPredicate:predicate]];    if (_screenArray.count>0) {        QHPiBuriedTreasureEditViewController *editVC = [[QHPiBuriedTreasureEditViewController alloc] initWithNibName:@"QHPiBuriedTreasureEditViewController" bundle:nil];        editVC.resultArray = [NSMutableArray arrayWithArray:_screenArray];        __weak typeof(self) weakSelf = self;        [editVC deleteSuccess:^{            __strong typeof (self)strongSelf = weakSelf;            [strongSelf updateRefrensh];        }];        [self.navigationController pushViewController:editVC animated:YES];    }else {        [MBProgressHUD showMessag:QHLocalizedString(@"没有可以编辑的记录", nil) toView:self.view afterDelay:hiddenMBPTime];    }    }- (void)updateRefrensh {    _pageIndex = 1;    [self loadMyMineListRequest];}

?⛽️

转载于:https://my.oschina.net/u/2519763/blog/1556066

你可能感兴趣的文章