tableView的批量编辑和左滑删除的一些注意点

1、批量编辑操作状态下cell不会自动右移(如果有左滑删除遇到类似问题应该解决方法也一样)

之前项目中用到批量删除,发现在编辑模式的时候cell不会自动右移,检查cell是不是加在contentView上的,还有约束的时候是不是根据contentView来进行约束的

2、  当对cell的cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator属性进行赋值时,cell的contentView会自动右移一段距离,因此如果用contentView对cell的子控件进行约束时,会和预期效果不一样(cell的contentView感觉会和cell本身的尺寸会小一点。)

3、如果想对左滑删除的按钮样式进行改变的话,可以在cell的layoutSubviews进行相关操作。

//#pragma mark - 自定义删除按钮样式

- (void)layoutSubviews {

  [super layoutSubviews];

  [self dealDeleteButton];

}

#pragma mark - 自定义删除按钮样式

- (void)dealDeleteButton{

    for (UIView *subView in self.subviews) {


        if ([subView isKindOfClass:NSClassFromString(@"UITableViewCellDeleteConfirmationView")]) {

         CGRect frame = subView.frame;

         frame.origin.y = self.backImage.frame.origin.y;

          frame.size.height = self.backImage.frame.size.height;

           subView.frame = frame;

////            subView.backgroundColor = [UIColor blueColor];


        for (UIButton *button in subView.subviews) {


               if ([button isKindOfClass:[UIButton class]]) {


////                    button.backgroundColor = [UIColor blueColor];

////                    button.titleLabel.font = [UIFont systemFontOfSize:11.0];


              }

          }

       }

  }

}

4、可以在cell内部实现以下方法对cell的尺寸及位置进行改变

-(void)setFrame:(CGRect)frame{

  frame.size.height -=10;

frame.origin.x += 7;

frame.size.width -= 14;

 frame.origin.y += 10;

[super setFrame:frame];

}

5、批量编辑

设置tableView的edit属性为可编辑模式,然后设置其属性allowsMultipleSelectionDuringEditing为YES,则会出现打勾的选项选择,此时点击会有多选的效果,选中的cell会打上勾,若要改变勾的颜色,可是设置cell的tintColor,改变cell的选中样式可以设置cell.selectedBackgroundView = [[UIView alloc] init]属性;如果allowsMultipleSelectionDuringEditing为NO,则出现的是减号,此时点击会有左滑删除的效果;

然后可以用

//        NSArray *indexPaths = [self.liftTbaleView indexPathsForSelectedRows];

/获得所有被选中的行,通过

// 遍历所有的行号

      for (NSIndexPath *path in indexPaths) {

           [self.deletedDeals addObject:self.datas[path.section]];

        }

就可以对所选中的cell进行相关操作。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容