2009-10-12 92 views
0

我這樣做編程方式顯示的圖像的圖像加載到的tableview細胞:中的tableview細胞

UIImage *image = [UIImage imageNamed:@"myimage.png"]; 
UIImageView *imageView = [[UIImageView alloc] initWithImage:image]; 
imageView.frame = CGRectMake(0, 0, cell.frame.size.width, cell.frame.size.height); 
imageView.contentMode = UIViewContentModeScaleToFill; 
[cell addSubview:imageView]; 
[imageView release]; 

return cell; 

但是,沒有圖像顯示爲單元格背景。這是在一個新的導航應用程序。以上看起來就像使用自定義單元格時Interface Builder中的步驟。該圖像位於應用程序包中。我究竟做錯了什麼?

回答

2

你們是不是要設置單元格的背景,或者只是添加圖像?如果您嘗試設置其背景,則應使用cell.background屬性。

 
imageView.frame = cell.bounds; 
imageView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; 
cell.backgroundView = imageView; 

+0

我想有單元格背景爲圖像。我在你的代碼中混合,但仍然沒有圖像。 – 4thSpace 2009-10-12 15:27:41