Hi. I've been drawing custom table cells (using the samples from apple as a base) and have now come to having to do a cell which displays an image from a URL - each cell would have a different image (based on some data it has) but all the cells are the same and so the same reuse id.
What's the correct structure for doing this? Obviously I need to load the image in a new thread. I've got the following function so far sitting in the cells view class which is run in its own thread:
- (void)loadImage
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
self.img = [UIImage imageWithData: [NSData dataWithContentsOfURL: [NSURL URLWithString: [myProduct objectForKey:@"ImagePath"]]]];
[self setNeedsDisplay];
[pool release];
}
When I call this from the drawRect function itself (which is bad) then it "works", but this obviously gets called every time anything happens (selection etc.). If I put it in the init function of the cells uiview, then it only gets called for the first 8 cells and then they're reused. Other variations ended up making the image not get 'reset' when the cell is reused and so the same 8 images repeat down the table (although the other text updates).
I'm not worried about caching for the moment, but are there any samples of how to do this, or can anyone point me in the right direction? Thanks.