不要使用
UIColor *bgColor = [[UIColor alloc] initWithWhite:1 alpha:0.0];
historyTable.backgroundColor = bgColor;
只需使用:
historyTable.backgroundColor = [UIColor clearColor];
这也清理了你创建的内存泄漏问题。
如何移除 UITableView 的背景视图?
xxx.backgroundView = nil;
在 iPad 构建中是必需的。在编译以在 iPad 和 iPhone 上运行时,请检查 tableView 是否响应具有 ... 的选择器。
if ([self.tableView respondsToSelector:@selector(setBackgroundView:)]) {
[self.tableView setBackgroundView:nil];
}
在将两者设置为nil/clear之后,它最终对我起作用了:
[myTableView setBackgroundView:nil];
[myTableView setBackgroundColor:[UIColor clearColor]];
我遇到了这个问题,发现使用以下两种方法没有区别:
[[UIColor alloc] initWithWhite:1 alpha:0.0];
并且使用:
[UIColor clearColor];
我尝试了这两种方法,但是在我的表视图中仍然有小黑角。
我也尝试了建议的将backgroundView设置为nil,但这也没有起作用。
我通过在cellForRowAtIndexPath方法中将各个单元格的背景设置为透明来解决了这个问题:
cell.backgroundColor = [UIColor clearColor];
当然,这样做的副作用是您的细胞本身也是透明的,这对于每个人来说都不是理想的,但在这种情况下对我来说还可以接受。
[UIColor colorWithWhite:0 alpha:0]
也可以使用,因为这实际上就是[UIColor clearColor]
的等价形式。由于某些疏忽,具有不同 RGB 值但 alpha 为 0 的颜色并不相等。 - user102008