UITableView performance issue

Discussion in 'iPhone/iPad Programming' started by nashyo, Feb 15, 2012.

  1. macrumors 6502

    nashyo

    Joined:
    Oct 1, 2010
    Location:
    Bristol
    #1
    Hi,

    When I segue to a table view controller that contains the following dynamic table view cell

    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];
        }
        
        // Configure the cell...
        Content *tc = [totalContent objectAtIndex:indexPath.row];
        cell.imageView.image = tc.Image1;
        cell.textLabel.text = tc.QuestionName;
        cell.detailTextLabel.text = tc.QuestionSubName;
        
        return cell;
    }
    the 29 rows that load appear with a preview image, positioned to the left of my text. By tapping each row, the image object is passed to the next view, using a prepareforsegue method.

    On first load into the table view, the performance stutters and freezes and the user scrolls down. Once the user reaches the bottom of the table view, and all the preview images have loaded into memory, the performance stabilises and scrolling is smooth.

    I'm trying to find a way to improve performance. Should I save these images to file, then read them from file in the above method? Can someone help me understand how I can improve performance of my table view in iOS please?

    Thanks
    Rob
     
  2. macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #2
    Async image loading tableview, or lazy loading tableview, maybe that helps you a bit without giving you the exact code :) (hint: google those words).
     
  3. thread starter macrumors 6502

    nashyo

    Joined:
    Oct 1, 2010
    Location:
    Bristol
    #3
    Ha, I actually appreciate this. Self-learning things like this is a big effort and it's easy to lose your way. Thanks.
     
  4. thread starter macrumors 6502

    nashyo

    Joined:
    Oct 1, 2010
    Location:
    Bristol
    #4
    The lazy table view method is interesting, but the apple music app doesn't perform that way. In album view, the images are instantly displayed. How does apple pull this off?
     
  5. xStep, Feb 16, 2012
    Last edited: Feb 16, 2012

    macrumors 68000

    Joined:
    Jan 28, 2003
    Location:
    Less lost in L.A.
    #5
    Magic doesn't really exist. ;)

    Perhaps it only appears to load instantly. Perhaps the thumbnails are so small that they load very fast. Perhaps they are using larger images made up of smaller thumbnails, allowing them to load a group. None of this excludes that Apple is using Async. They likely are in some way.

    There is at least one WWDC video that discusses this tactic. I'd be guessing to say it is Practical Drawing for iOS Developers, or UITableView Changes, Tips & Tricks from WWDC 2011, or Advanced Performance Optimization on iPhone OS, Part 1 or Part 2, or Performance Optimization on iPhone OS, or Mastering Table Views from WWDC 2010. That last one sounds like a good place to start.

    Sorry I couldn't be more helpful on the video or other direction. I just remember watching these and being impressed with with samples as they demonstrated the techniques.
     
  6. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #6
    Plus, Apple is able to do things, via private APIs, that us mere developers are not.
     
  7. thread starter macrumors 6502

    nashyo

    Joined:
    Oct 1, 2010
    Location:
    Bristol
    #7
    I still haven't figured this out. However, someone posted on stack forum, that it might be a good idea to have a separate array of my images already scaled to the appropriate size - and have them load into the tablleviewcell image.

    I'm going to try this. Does anyone know the dimensions of the image in a table view cell? It's hard to find.

    The inspector in Xcode shows the dimensions of the table view cell to be 44x22. I've seen several posts on this and all say different values. Some say 88x88 pixels, but the image doesn't appear square in the table view cell, so this must be wrong.
     
  8. thread starter macrumors 6502

    nashyo

    Joined:
    Oct 1, 2010
    Location:
    Bristol
    #8
    I images used with dimensions 88x59 pixels at 31ppi, and now it's all working fine.

    I learned about multi-threading basics from the book 'beginning IOS 5 Developerment' by Dave, Mark and Jeff. It's a really good book. My app is pretty small and multithreading manipulations is cool, but inappropriate for what I need right now.
     

Share This Page