UITableView and lazy loading question

Discussion in 'iOS Programming' started by vcanic, Apr 6, 2010.

  1. vcanic macrumors newbie

    Joined:
    Feb 4, 2010
    #1
    Hello,

    I have some questions about efficiently loading entries for a UITableView.
    First I do a request to a server, the server gives me an XML output with about 500 to 1000 entries. Each entry should be represented as clickable/touchable item in the UITableView.

    What is the best way to do this, as efficient as possible? I doubt loading the 500 to 1000 entries at once is a good idea.
    Should I do something with lazy loading, if so..does the UITableView support lazy loading.

    I have also taken a look at the App store on the iPhone as an example. There you get 25 entries and at the bottom you can click on a "Show 25 more..." option. Is this perhaps a better approach?

    Any help and suggestions are welcome since I am new to this. Thanks in advance.
     
  2. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
  3. AndyCodez macrumors regular

    Joined:
    Aug 6, 2009
    #3
    Hopefully your data source uses Pages. I find that loading 25 pages is quick and nice. So hopefully you don't download that much data at once and then show the 25 ;p
     
  4. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #4
    UITableViews, by their very nature, support lazy-loading, as implemented through the UITableViewDataSource protocol. They only call the tableView:cellForRowAtIndexPath: method for cells that appear onscreen. So, even if your data source has 1000 items, if the table view can only display, say, 10 cells on the screen, then it will only call that method for those 10 cells. And, if coding in the recommended way, it will reuse cells when needing new ones. Make sure you have read through the Table View Programming Guide for iPhone OS.
     
  5. vcanic thread starter macrumors newbie

    Joined:
    Feb 4, 2010
    #5
    Thank you for the replies. How the UITableView works is becoming clear to me.

    I have one more question though:
    Let's say that I have 500 entries stored in an array (transfered from a remote server). So the UITableView displays 500, but when I browse to the bottom of the UITableView, it should buffer and load the next 500 entries. This means that the UITableView should load 500 entries at once, and when the bottom of the UITableView is reached it should load the next 500.

    What is the best way of doing this? Since this means it has to expand itself everytime it reaches the bottom.

    Is this even possible?
     
  6. AndyCodez macrumors regular

    Joined:
    Aug 6, 2009
    #6
    I think I understand what you are getting at. On most of my apps /tables i do a cell to "load more" click that and it loads more. Basically just do checks to see which row you are on and once you reach a specified row start loading the next batch of rows.
     
  7. vcanic thread starter macrumors newbie

    Joined:
    Feb 4, 2010
    #7
    I think you do understand what I am getting at.

    So when I reach row 500, I should display a 'load more' button in row 501. And when the 'load' more button is pressed I should insert the next 500 rows, and so on.

    Is that what you mean?
     
  8. AndyCodez macrumors regular

    Joined:
    Aug 6, 2009
    #8
    Pretty much, but you don't necessarily even need to have them press the row to do it. But yes that is exactly what I am getting at. Generally if your loading from a datasource they will use pages so say each page has 20 rows, then each 20 rows shown you get the next set of data via page 2.
     
  9. vcanic thread starter macrumors newbie

    Joined:
    Feb 4, 2010
    #9
    Sorry for the late reply, was on vacation.

    That is understandable. So basically what you mean is after the first 20 entries are shown it should proceed by loading the next 20 items in the datasource?

    Does UITableView have this functionality? To see if the current 20 items are shown? Or is that something I should implement myself?
     
  10. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #10
    Did you get a chance to read the Table View Programming Guide while you were on vacation? :)
     

Share This Page