Using:
Have 1 image and text on every cell. Images are not getting resized while scrolling. Have two versions of images image.png and [email protected].
The custom cell was managed by drugging UIImageView and UILabel in storyboard.
Code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
Continent *continent=[self.items objectAtIndex:[indexPath row]];
ContinentCell *cell = (ContinentCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
cell.continentName.text=continent.continentName;
cell.textView.text=continent.countriesHash;
cell.imageView.image=[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:continent.continentImage ofType:@"png"]];
return cell;
}
Where's the evil? Thank you in advance.
[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:continent.continentImage ofType:@"png"]];
Is expensive. You want to load the image the image asynchronously in the background then present it on the main thread when ready.
Here's a very rough solution
cell.imageView.image = nil;
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
UIImage * img = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:continent.continentImage ofType:@"png"]];
dispatch_sync(dispatch_get_main_queue(), ^{
cell.imageView.image = img;
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With