0

Im trying to load a single image into the grouped table cell. I found a piece of code on the internet and modified it. Original code is using UIViews to display image, which is not what I need, however original code works of course. PLease help me to make this code work to display an image in a sigle cell for grouped tableview. My TableView has only one row and it has UITableViewCellStyleDefault style.

Original Code

Here is my modified method, this is the core method.

- (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;
}

This is how I use it to display image in my TableView Cell cellForRowAtIndexPath method.

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;
4

1 に答える 1

0

あなたが投稿したそのコードでは、AsyncImageView のイメージは、接続の読み込みが完了して実際にイメージが作成されるまで設定されません。問題は、その画像をすぐにセルに設定していることです。それはうまくいきません!

カスタム セル クラス (サブクラス UITableViewCell) を作成し、そのセルをテーブルで使用します。カスタム セルの使用方法と、それらをビューでレイアウトする方法を示すサンプル コードが多数あります。UITableViewCell の標準の imageView を使用する代わりに、独自のレイアウトを作成し、AsyncImageView を使用して画像を表示します。その後、動作するはずです。

于 2009-12-03T14:36:28.720 に答える