2012-08-11 148 views
0

我在我的iOS應用程序中看到了設置視圖,由UITableView提供。這個應用程序是通用的,所以你可以在iPhone和iPad上運行它。該表應該具有自定義背景。並使用此代碼設置圖像的背景:iPad上UITableView的背景圖像

table.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"settings_bg"]]; 

這是iPhone OK:

enter image description here

但在iPad這樣的背景是灰色的!

enter image description here

爲什麼?我應該如何爲iPad設置自定義背景?日Thnx。

回答

1

這在某種程度上是分組模式下iPhone和iPad UITableView行爲的已知區別。使用此代碼,而不是(或類似):

if ([self.tableView respondsToSelector:@selector(backgroundView)]) { 
    [self.tableView setBackgroundView:nil]; 
    UIView* bkgView = [[[UIView alloc] initWithFrame:self.tableView.bounds] autorelease]; 
    bkgView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:...]]; 
    [self.tableView setBackgroundView:bkgView]; 

} 
+0

仍然沒有工作的iPad ..但確定爲iPhone – 2012-08-11 08:42:34

+0

對不起,這是爲我工作... – sergio 2012-08-11 10:16:17

+0

什麼或者是像你引用?或者你的意思是說,作爲佔位符? – 2012-08-11 12:34:41