删除分组UITableViewCell上的重新排序控件旁边的白线

Jus*_*ams 7 iphone cocoa-touch uitableview

我为我的桌子构建了一个自定义UI,它有一个更暗的UI和一个自定义的accessoryView.当我将表格置于编辑模式时,重新排序控件左侧有一条白线,我似乎无法摆脱它.

tableView:accessoryTypeForRowWithIndexPath:似乎不适合摆脱它,因为我没有使用标准的UITableViewCellAccessoryType,所以我不知道我能做些什么来让它不显示在我的单元格上.

白线示例http://secondgearsoftware.com/attachments/stackoverflow_reorder.png

Mat*_*her 12

发生的事情是,当UITableViewCell显示重新排序控件时,它还会在其子视图数组中添加一个空的,1像素宽的白色UIView.

直言不讳:这是Apple应该修复的错误.

但是,您可以通过每次出现时查看恼人的视图并将其背景颜色设置为透明来绕过它.快速提示:恼人的白色视图始终是UITableViewCell子视图数组中的最后一个,并且始终为1像素宽.我们将用它来找到它.

当您打开表格的编辑时,使所有可见的令人讨厌的1像素视图透明.因此,在表上切换"编辑"模式的操作方法可能如下所示:

- (IBAction)edit:(id)sender
{
    [tableView setEditing:!tableView.editing animated:YES];

    for (UITableViewCell *cell in [tableView visibleCells])
    {
        if (((UIView *)[cell.subviews lastObject]).frame.size.width == 1.0)
        {
            ((UIView *)[cell.subviews lastObject]).backgroundColor =
                [UIColor clearColor];
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

并且通过在UITableViewDelegate中实现它们,可以看到所有新视图的可见性:

- (void)tableView:(UITableView *)tableView
    willDisplayCell:(UITableViewCell *)cell]
    forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (((UIView *)[cell.subviews lastObject]).frame.size.width == 1.0)
    {
        ((UIView *)[cell.subviews lastObject]).backgroundColor =
             [UIColor clearColor];
    }
}
Run Code Online (Sandbox Code Playgroud)

修复这个问题的这个黑客是相当无害的,如果Apple将来修复这个bug(停止添加烦人的1像素视图),这段代码应该悄悄地停止做任何事情.