Ios 当显示行操作时,单元格下的UITableView背景可见

Ios 当显示行操作时,单元格下的UITableView背景可见,ios,uitableview,Ios,Uitableview,我有UITableView,有白色的部分标题和黑色的单元格。桌子的背景也是白色的。这样做是为了在表反弹时节标题看起来很好: 我在表中的行中添加了几个操作()。但是,有一个问题:由于行是暗的,当我滑动以显示行编辑操作时,第一个操作之间存在白色间隙: (请注意,单元格及其内容视图在XIB文件中设置了相同的深色背景色。) 在检查视图层次结构之后,我发现在显示操作按钮之后,单元格缩小了,我通过这个间隙看到的是实际的表视图 由于无法更改表视图的背景,我尝试在所有其他视图下面添加自定义背景视图: sel

我有
UITableView
,有白色的部分标题和黑色的单元格。桌子的背景也是白色的。这样做是为了在表反弹时节标题看起来很好:

我在表中的行中添加了几个操作()。但是,有一个问题:由于行是暗的,当我滑动以显示行编辑操作时,第一个操作之间存在白色间隙:

(请注意,单元格及其内容视图在XIB文件中设置了相同的深色背景色。)

在检查视图层次结构之后,我发现在显示操作按钮之后,单元格缩小了,我通过这个间隙看到的是实际的表视图

由于无法更改表视图的背景,我尝试在所有其他视图下面添加自定义背景视图:

self.tableBackgroundView = [[UIView alloc] initWithFrame:self.tableView.bounds];
self.tableBackgroundView.backgroundColor = [UIColor redColor];
self.tableBackgroundView.autoresizingMask = UIViewAutoresizingFlexibleSize;
[self.tableView addSubview:self.tableBackgroundView];
[self.tableView sendSubviewToBack:self.tableBackgroundView];
然而,它并没有起到很好的作用


是否有其他方法可以“隐藏”单元格之间的空白及其编辑操作?

我通过在
表格视图:willDisplayCell:
中的每个单元格后面添加一个背景来克服这一问题

这是我的最终代码:

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell
forRowAtIndexPath:(NSIndexPath *)indexPath {
    // Remove background gaps on the left and right sides of row separators on iOS < 10.
    cell.backgroundColor = cell.contentView.backgroundColor;

    // Remove another gap in row background when swiping in to the left to start editing.
    CGRect cellFrame = [cell convertRect:cell.bounds toView:tableView];
    UIView *backgroundView = self.cellBackgroundViews[indexPath];
    if (backgroundView == nil) {
        backgroundView = [[UIView alloc] init];
        self.cellBackgroundViews[indexPath] = backgroundView;
    }
    backgroundView.frame = CGRectInset(cellFrame, 0, -1);
    backgroundView.backgroundColor = cell.contentView.backgroundColor;
    [self.tableView addSubview:backgroundView];
    [self.tableView sendSubviewToBack:backgroundView];
}

- (void)tableView:(UITableView *)tableView didEndDisplayingCell:(UITableViewCell *)cell
forRowAtIndexPath:(NSIndexPath *)indexPath {
    UIView *backgroundView = self.cellBackgroundViews[indexPath];
    [backgroundView removeFromSuperview];
}
-(void)tableView:(UITableView*)tableView将显示单元格:(UITableView单元格*)单元格
ForRowatineXpath:(NSIndexPath*)indexPath{
//移除iOS<10上行分隔符左右两侧的背景间隙。
cell.backgroundColor=cell.contentView.backgroundColor;
//当向左滑动开始编辑时,删除行背景中的另一个间隙。
CGRect cellFrame=[cell convertRect:cell.bounds-toView:tableView];
UIView*backgroundView=self.cellBackgroundViews[indexPath];
如果(背景视图==nil){
backgroundView=[[UIView alloc]init];
self.cellbackgroundview[indexPath]=背景视图;
}
backgroundView.frame=CGRectInset(cellFrame,0,-1);
backgroundView.backgroundColor=cell.contentView.backgroundColor;
[self.tableView addSubview:backgroundView];
[self.tableView sendSubviewToBack:backgroundView];
}
-(void)tableView:(UITableView*)tableView DiEndDisplayingCell:(UITableViewCell*)单元格
ForRowatineXpath:(NSIndexPath*)indexPath{
UIView*backgroundView=self.cellBackgroundViews[indexPath];
[背景视图从SuperView移除];
}

@KKRocks你什么意思?如果你说的是“编辑”和“清除”按钮,它们是
UITableViewRowAction
:是的,我知道,但我想知道如何添加此按钮……请输入代码,以便我了解你的问题。