我为我的表格构建了一个自定义 UI,它具有较暗的 UI 和自定义的accessoryView。当我将表格置于编辑模式时,重新排序控件左侧有一条白线,我似乎无法摆脱它。
tableView:accessoryTypeForRowWithIndexPath: 似乎不适合摆脱它,因为我没有使用标准的 UITableViewCellAccessoryType,所以我不确定我可以做什么来获取它不要出现在我的细胞上。
最佳答案
发生的情况是,当 UITableViewCell 显示重新排序控件时,它还会向其 subview 数组添加一个空的、1 像素宽的白色 UIView。
坦率地说:这是苹果应该修复的错误。
但是,您可以通过每次出现该烦人的 View 并将其背景颜色设置为透明来解决它。 快速提示:烦人的白色 View 始终是 UITableViewCell subview 数组中的最后一个,并且始终为 1 像素宽。我们将用它来找到它。
当您打开表格编辑功能时,请将所有可见的烦人的 1 像素 View 设为透明。因此,在表格上切换“编辑”模式的操作方法可能如下所示:
- (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];
}
}
}
通过在 UITableViewDelegate 中实现此方法,当所有新 View 变得可见时,继续执行此操作:
- (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];
}
}
这个解决问题的 hack 是相当无害的,如果 Apple 将来修复这个 bug(停止添加烦人的 1 像素 View ),这段代码应该悄悄地停止做任何事情。
关于iphone - 删除分组 UITableViewCell 上重新排序控件旁边的白线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/874589/