Loading over a thousand Cells! in tableView

Discussion in 'iOS Programming' started by mraheel, May 18, 2009.

  1. mraheel macrumors regular

    Apr 18, 2009

    I'm trying to load from SQL, data of over 1000 rows! Yea, if i were working on a webserver, that would be a different ordeal.. i wouldnt worry so much..

    Since my sqlite db is gonna be bundled with the app itself, i'm not sure how to proceed with this.
    I've worked with the traditional methods from sqlitebooks tutorial and populated a tableView with over a 1000 rows, or even more. Ofcourse, search will be there.. I'm afraid will I be loading alot into memory? using alot of resources

    But is there anything i should be doing differently inorder to keep the app safe, from memleaks, perhaps a different approach?? any alternatives?

    any help is appreciated
  2. plinx0r macrumors member

    Jul 11, 2008
    Cells are populated when they appear into view via the following method:

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
    In your case all 1000 rows would not be generated at the same time. Personally, I would populate the data array or dictionary on a separate thread when loading the app. The method above will take care of the rest by only referencing the data as their respective rows are brought into view. Also, be sure to dequeue reusable cells.
  3. PhoneyDeveloper macrumors 68040


    Sep 2, 2008
    The number of rows in your table isn't important. I have a table that can display 80,000 rows, based on user data.

    The thing is to load your data in chunks. Can your user scroll down through 1000 rows? If not, do you have an index? Load the row data for each section as the table asks for it. Otherwise, load the data in chunks of some size like 20 or 50 rows.

    Your table can only display ten or twelve rows at a time. That's all the data that has to be in memory at one time.
  4. mraheel thread starter macrumors regular

    Apr 18, 2009
    I already use NSMutableArray that gets everything from SQL

    So your saying I load the data kinda dynamically as the user scrolls? And I classify the cells with an index.
    It would be kinda tough for me to that. I'm guessing I need to figure out a way where if a user scrolls, the app should detect it and retrieve new cells and load it!.

  5. dejo Moderator


    Staff Member

    Sep 2, 2004
    The Centennial State
    That's pretty much already taken care of for you via the UITableViewDataSource protocol methods.
  6. PhoneyDeveloper macrumors 68040


    Sep 2, 2008

    Is your method of loading everything at once in an array working or not?

    In fact it should be simple to fill your array with [NSNull null], one for each row. Then when you need the data for a row check if it's been loaded or not, if not then load a chunk of rows into the array, replacing the null sentinel values. That's one way to load the data in chunks as needed.
  7. mraheel thread starter macrumors regular

    Apr 18, 2009

    the simple method i'm using is fine, working. It takes a while to load though in the simulator. But theres not gonna be any changes once it loads. So this is definitely ok. I was only looking less memory using methods.
    I'll give what you said a try...

Share This Page