TableView scroll is choppy

Discussion in 'iOS Programming' started by jackhdev, Mar 4, 2012.

  1. jackhdev macrumors 6502

    Apr 9, 2011
    Bismarck, North Dakota
    I put UIImageViews into my table view cells and scrolling has been very choppy. I'm assuming it's because the images are being reloaded each time their cell appears, but how would I preload/cache the images? Thanks for your help.

    // Customize the appearance of table view cells.
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
        NSString *CellIdentifier = @"Cell";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil) {
            cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
        // Set up the cell...
    	NSDictionary *dic = [self.issues objectAtIndex:indexPath.row];
        cell.text = [dic objectForKey:@"Date"];
        cell.imageView.image = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/issues/%@/cover.png", documentsDirectory, [dic objectForKey:@"Directory Name"]]];
        return cell;
    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
            return 150;
  2. pmau macrumors 65816

    Nov 9, 2010
    Excuse my answer, but there's a complete iOS sample application on apple's developer site that explain exactly what you are trying to do.

    Hint: It uses GCD to load images in the background, displaying a placeholder image.
  3. jackhdev thread starter macrumors 6502

    Apr 9, 2011
    Bismarck, North Dakota
    Do you know the name of it?
  4. pmau macrumors 65816

    Nov 9, 2010

    I hope the link works OK.


    There was also some advanced sample code from WWDC 2010.
    I'll try to find it...
  5. PhoneyDeveloper macrumors 68040


    Sep 2, 2008
    LazyTableImages shows how to download images from the internet to display in your table. Just loading them from disk shouldn't be such a problem. Just cache the images in your data model. You can load them in cellForRowAtIndexPath if they haven't already been loaded, if you like. Or if there's a better place to pre-load them you might do that in viewDidLoad. Depends how many rows there might be. If the same images might be used in multiple rows then it might make sense for the view controller to cache them also.

Share This Page