我試圖將單個圖像加載到分組表格單元格。我在互聯網上找到了一段代碼並對其進行了修改。原始代碼使用UIViews來顯示圖像,這不是我所需要的,但是原始代碼當然是有效的。 PLease幫助我使這個代碼工作在一個單獨的tableview的單元格中顯示圖像。我的TableView只有一行,它有UITableViewCellStyleDefault樣式。異步圖像加載到TableView單元格
這裏是我修改的方法,這是核心的方法。
- (void)connectionDidFinishLoading:(NSURLConnection*)theConnection
{
[connection release];
connection=nil;
UIImage *img = [UIImage imageWithData:data];
self.image = img;
self.frame = self.bounds;
[self setNeedsLayout];
[data release];
data=nil;
}
這就是我如何使用它在我的TableView Cell cellForRowAtIndexPath方法中顯示圖像。
CGRect frame;
frame.size.width=75; frame.size.height=75;
frame.origin.x=0; frame.origin.y=0;
AsyncImageView* asyncImage = [[[AsyncImageView alloc] initWithFrame:frame] autorelease];
[asyncImage loadImageFromURL:imageURL];
cell.imageView.image = asyncImage.image;
我的評論是,只是在細胞中添加異步,而不是像這樣異步的圖像 [cell addSubview:asyncImage]; 而是這行代碼cell.imageView.image = asyncImage.image; – 2012-04-17 05:49:29