English 中文(简体)
Asynchronous image load into TableView cell
原标题:

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;
问题回答

In that code you posted, the image of the AsyncImageView doesn t get set until after the connection finishes loading and it actually creates the image. Problem is, you re setting it s image into the cell immediately. That s not going to work!

You re going to want to make a custom cell class (subclass UITableViewCell) and use that cell in your table. There s lots of sample code showing how to use custom cells and lay them out with views. Instead of using UITableViewCell s standard imageView, create your own layout and use an AsyncImageView to show your image. Then it should work.





相关问题
Code sign Error

I have created a new iPhone application.I have two mach machines. I have created the certificate for running application in iPhone in one mac. Can I use the other mac for running the application in ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

将音频Clips从Peter改为服务器

我不禁要问,那里是否有任何实例表明从Peit向服务器发送音响。 I m不关心电话或SIP风格的解决办法,只是一个简单的袖珍流程......

• 如何将搜查线重新定位?

我正试图把图像放在搜索条左边。 但是,问题始于这里,搜索条线不能重新布署。

热门标签