iOS UITableView 在编辑状态下 删除与cell重叠问题

UITableView编辑状态下给提了删除与cell重叠问题bug
项目中原解决方法是这样的
在自定义cell中重写这个方法

- (void)layoutSubviews {
    [super layoutSubviews];
    
    for (UIView *subview in self.subviews) {
        for (UIView *subview2 in subview.subviews) {
            if ([NSStringFromClass([subview2 class]) isEqualToString:@"UITableViewCellDeleteConfirmationView"]) {
                [subview bringSubviewToFront:subview2];
            }
        }
    }
}

但上面那个方法只在iOS7好用,iOS8,iOS9上都不好用
下面给出了两种解决方式
方法1(自定义cell中重写方法)

- (void)layoutSubviews {
    [super layoutSubviews];
  
    if (self.isEditing) {
        [self sendSubviewToBack:self.contentView];
    }
}

方法2(重写cell状态将要转换时调用的方法)

- (void)willTransitionToState:(UITableViewCellStateMask)state {
    [super willTransitionToState:state];
    if (state == 3) {//state是枚举,3是UITableViewCellStateShowingDeleteConfirmationMask
        dispatch_async(dispatch_get_main_queue(), ^{
            [self sendSubviewToBack:self.contentView];
        });
    }
}


你可能感兴趣的:(iOS UITableView 在编辑状态下 删除与cell重叠问题)