2010-03-07 62 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