Note that there are some explanatory texts on larger screens.

plurals
  1. POloading dynamic images into a custom UITableViewCell slows scrolling
    primarykey
    data
    text
    <p>I am loading some images dynamically into a UITableView and creating some simple custom cells.</p> <p>In the cellForRowAtIndexPath method I am passing through the content for each cell like so:</p> <pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { ImagesCell *cell = (ImagesCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { NSUInteger row = [indexPath row]; Playlist *playlist = [[playlistManager playlists] objectAtIndex:row]; NSString *thumbPath = [(NSString *) playlist.imagePath stringByAppendingString: @"100x75.png"]; NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"ImagesCell" owner:self options:nil]; cell = [nib objectAtIndex:0]; cell.topLabel.text = playlist.title; cell.bottomLabel.text = playlist.artistName; cell.customImageView.image = [UIImage imageWithData: [NSData dataWithContentsOfURL: [NSURL URLWithString: thumbPath]]]; cell.opaque = YES; cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton; } return cell;} </code></pre> <p>I am also changing the height like so:</p> <pre><code>- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { CGFloat result; result = ROW_HEIGHT; return result;} </code></pre> <p>This all works - in that it loads / shows the content - but when I test it on the device it paused on each cell redraw slightly, causing pretty rough scrolling.</p> <p>Can anyone show me how to load the image in a way that would fix this? I have had a look at some asynchronous examples and apples LazyLoading example but this is my first iphone proj and find it a bit tough going.</p> <p>If anyone has examples or some code to share that would be a great help.</p> <p>Many thanks</p> <p><em>UPDATE</em></p> <p>The answer selected works but loads all the items in before showing the UITableView.</p> <p>After much cutting and pasting and version control, the best solution seems to be <a href="http://www.markj.net/hjcache-iphone-image-cache" rel="nofollow">MarkJNet's HJCache</a></p> <p>This gives image caching as well as asynchronous loading, its very easy to implement (although I havent got it working with a nib yet but I am hopeful it shouldn't be too tough.</p> <p>Hope that helps someone.</p> <p>Thanks again to @RedBlueThing and @Marcelo-Alves</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload