2010-03-07 63 views

回答

37

而不是使用

UIColor *bgColor = [[UIColor alloc] initWithWhite:1 alpha:0.0]; 
historyTable.backgroundColor = bgColor; 

只需使用:

historyTable.backgroundColor = [UIColor clearColor]; 

这也清除了你创建内存泄漏。

+1

非常感谢你。顺便说一句,我后来bgColor,但感谢您的关注;)。 – Jacek 2010-03-07 12:50:35

+0

不错的一个..正是我今天需要的 – Scrimmers 2010-08-27 11:22:10

+6

注意:[UIColor clearColor]目前必须在代码中设置,如果在界面生成器中设置了clearColor,则它不起作用。 – 2011-01-07 08:57:59

35

删除的UITableView backgroundView

xxx.backgroundView = nil; 

这是必要的iPad版本。当编译到iPad和iPhone上运行,检查的tableView响应与选择...

if ([self.tableView respondsToSelector:@selector(setBackgroundView:)]) { 
    [self.tableView setBackgroundView:nil]; 
} 
+0

setBackgroundView:可从iOS 3.2下载,不能固定到iPad,不是吗?为什么应该使用这个检查? – adruzh 2012-03-16 10:28:31

3

我有这个问题,并发现有使用没有任何区别:

[[UIColor alloc] initWithWhite:1 alpha:0.0]; 

和使用:

[UIColor clearColor]; 

我尝试了这两个,并仍然有我的桌子上的小黑角。

我也尝试将backgroundView设置为无,如此建议,但这也不起作用。

我通过cellForRowAtIndexPath方法中的单个细胞的背景设置为透明的解决了这个:

cell.backgroundColor = [UIColor clearColor]; 

当然,这有副作用,你的细胞本身是透明的,这是不理想的每个人,但在这种情况下,我可以。

+0

使用分组式tableview时效果很好。+1 – 2013-07-09 08:43:24

8

对我来说finaly工作都设置为无/清除后:

[myTableView setBackgroundView:nil]; 
[myTableView setBackgroundColor:[UIColor clearColor]]; 
+0

将背景视图设置为零后,无需设置背景颜色清除。 – Will 2013-06-05 19:00:28

+0

在我的情况下,我不得不这样做,否则我会以白色背景结束。但那可能是一个特例。 – zero3nna 2013-06-07 13:37:58