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

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

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;
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

友情链接更多精彩内容