tableView批量删除,删除图片在右边

项目需求要求点击按钮,批量删图标在右边而不是默认的左边,蛋疼了2天,百度是找的都是在左边,终于解决

tableView批量删除,删除图片在右边_第1张图片
Simulator Screen Shot 2016年9月21日 下午2.52.06.png
使用Masonry 重置约束
#pragma mark - 编辑按钮事件
-(void)editBtnAction{
    //更改约束
    NSArray *cellArray = [self cellsForTableView:self.tableView];
    if ([self.editBtn.titleLabel.text isEqualToString:@"编辑"]) {
        for (StoreShopsListCell *cell in cellArray) {
            [UIView animateWithDuration:1 animations:^{
                [cell.deleteBgView mas_remakeConstraints:^(MASConstraintMaker *make) {
                    make.left.mas_equalTo(cell.contentView.mas_right).offset(-70);
                    make.top.equalTo(cell.contentView);
                    make.bottom.equalTo(cell.contentView).offset(1);
                    make.width.equalTo(cell.contentView);
                }];
                [cell.addBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
                    make.right.mas_equalTo(cell.contentView.mas_right).offset(-80);
                    make.bottom.mas_equalTo(cell.shopImageView.mas_bottom).offset(0);
                    make.width.height.mas_equalTo(20);
                }];
                [cell.contentLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
                    make.right.mas_equalTo(cell.contentView.mas_right).offset(-70);
                    make.left.mas_equalTo(cell.shopImageView.mas_right).offset(10);
                    make.top.mas_equalTo(cell.shopImageView.mas_top).offset(-3);
                    make.height.mas_equalTo(20);
                }];
            }];
    }
        [self.editBtn setTitle:@"完成" forState:(UIControlStateNormal)];
        [self.editBtn setTitleColor:UIColorFromRGB(0x00bb9c) forState:(UIControlStateNormal)];
    }else{
        [_editBtn setTitle:@"编辑" forState:(UIControlStateNormal)];
        [_editBtn setTitleColor:UIColorFromRGB(0x43515a) forState:(UIControlStateNormal)];
        for (StoreShopsListCell *cell in cellArray) {
            [UIView animateWithDuration:1 animations:^{
                [cell.deleteBgView mas_remakeConstraints:^(MASConstraintMaker *make) {
                    make.left.mas_equalTo(cell.contentView.mas_right).offset(0);
                    make.top.equalTo(cell.contentView);
                    make.bottom.equalTo(cell.contentView).offset(1);
                    make.width.equalTo(cell.contentView);
                }];
                [cell.addBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
                    make.right.mas_equalTo(cell.contentView.mas_right).offset(-10);
                    make.bottom.mas_equalTo(cell.shopImageView.mas_bottom).offset(0);
                    make.width.height.mas_equalTo(20);
                }];
                [cell.contentLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
                    make.right.mas_equalTo(cell.contentView.mas_right).offset(-10);
                    make.left.mas_equalTo(cell.shopImageView.mas_right).offset(10);
                    make.top.mas_equalTo(cell.shopImageView.mas_top).offset(-3);
                    make.height.mas_equalTo(20);
                }];
            }];
        }
    }
}

  • 获取去不cell的方法 包括看不到的cell
//获取所有包括看不到的cell
-(NSArray *)cellsForTableView:(UITableView *)tableView
{
    NSInteger sections = tableView.numberOfSections;
    NSMutableArray *cells = [[NSMutableArray alloc]  init];
    for (int section = 0; section < sections; section++) {
        NSInteger rows =  [tableView numberOfRowsInSection:section];
        for (int row = 0; row < rows; row++) {
            NSIndexPath *indexPath = [NSIndexPath indexPathForRow:row inSection:section];
            [cells addObject:[tableView cellForRowAtIndexPath:indexPath]];
        }
    }
    return cells;
}

你可能感兴趣的:(tableView批量删除,删除图片在右边)