I've been looking around the web to find some simple tutorials that explain how to download an image from the internet, cache it and then put it into a uitableview when it has finished. There are some overly complicated ones on the Apple Developer website and from them I have no idea what I'm looking for.
What I have at the moment is:
Code:
for(int i=0;i<[ImageXX count];i++)
{
TFHppleElement *ImageX = [ImageXX objectAtIndex:i];
NSString *Image = [ImageX content];
[imageArray addObject:Image];
}
Code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell...
NSUInteger row = [indexPath row];
cell.font=[UIFont fontWithName:@"Helvetica" size:15.0];
cell.textLabel.text = [Array objectAtIndex:row];
NSURL *url = [NSURL URLWithString:[imageArray objectAtIndex:row]];
NSData *imageData = [NSData dataWithContentsOfURL:url];
UIImage* imageView = [UIImage imageWithData:imageData];
[cell setImage: imageView];
return cell;
}
Of course doing it this way makes the scrolling completely laggy as the images get downloaded every time the cell with the image is visible. Using "imageNamed:" automatically caches the images except they have to be local. Can anyone point me to a nice straight forward example how to do it asynchronously or just cache the images as they download? Thanks