You can use Lazy Loading when you want to download images from the Internet.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { //All you reusable cell implementation here. //Since your Images sizes differ. Keep a custom Imageview if(![imagesForCategories containsObject:indexPath]) { customImageView.image = [UIImage imageNamed:@"default-image.png"]; NSMutableArray *arr = [[NSArray alloc] initWithObjects:[imageUrlArray objectAtIndex:indexPath.row],indexPath, nil]; [self performSelectorInBackground:@selector(loadImageInBackground:) withObject:arr]; [arr release]; } return cell; } - (void) loadImageInBackground:(NSArray *)urlAndTagReference { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSURL *imgUrl=[[NSURL alloc] initWithString:[urlAndTagReference objectAtIndex:0]]; NSData *imgData = [NSData dataWithContentsOfURL:imgUrl]; UIImage *img = [UIImage imageWithData:imgData]; [imgUrl release]; NSMutableArray *arr = [[NSMutableArray alloc ] initWithObjects:img,[urlAndTagReference objectAtIndex:1], nil ]; [self performSelectorOnMainThread:@selector(assignImageToImageView:) withObject:arr waitUntilDone:YES]; [arr release]; [pool release]; } - (void) assignImageToImageView:(NSMutableArray *)imgAndTagReference { [imagesForCategories addObject:[imgAndTagReference objectAtIndex:1]]; UITableViewCell *cell = [celebCategoryTableView cellForRowAtIndexPath:[imgAndTagReference objectAtIndex:1]]; UIImageView *profilePic = (UIImageView *)[cell.contentView viewWithTag:20]; profilePic.image = [imgAndTagReference objectAtIndex:0]; }
source share