Wait until data is loaded from a server with json

Discussion in 'iOS Programming' started by Mac2011, Jan 28, 2011.

  1. Mac2011 macrumors newbie

    Jan 11, 2011
    So my question is: How can I wait to load the tableview until the data is loaded.
    Unfortunately I can't use connectionDidFinishLoading in a while loop because it's a void message.
    Any suggestions?
  2. ChrisA macrumors G4

    Jan 5, 2006
    Redondo Beach, California
    On other platforms I've used, a writer can lock the table. It will not write until it gets the lock. The reader if it issues a read will block until the lock is removed by the writer. On many systems this is effisent as no polling is involved the system only checks when lock states change
  3. Mac2011 thread starter macrumors newbie

    Jan 11, 2011
    Thx. I'll try it. Maybe there is a way that I lock the "main" thread until a second thread is done or a queue of things it should do.
  4. cnstoll macrumors 6502

    Aug 29, 2010
    Sounds like you're going about it the wrong way. You should let the tableView go ahead and load empty when the view is loaded. Once the data has been downloaded and stored in your datasource you should set up a delegate method in your table view controller to update the table view to display your new data.

    A great way to update the table view is:

    [tableView beginUpdates];
    // insert some rows, do whatever updates
    [tableView endUpdates];
    That will animate all of the updates in the begin/end block in a very nice way. It's pretty neat. For more information check out the documentation on UITableView.

  5. Mac2011 thread starter macrumors newbie

    Jan 11, 2011
    Wirelessly posted (Mozilla/5.0 (iPod; U; CPU iPhone OS 4_3 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8F5153d Safari/6533.18.5)

    Yep. Now I got. Very simple. I created a NSoperationqueue in viewdidload and a delegate. after the connection did finish launching method, a method gets called to set the data for the table view and than reload its data. I think that's the best way to go and the UI doesn't get stuck either.
  6. PhoneyDeveloper macrumors 68040


    Sep 2, 2008
    If you like you can add a row to the table that says Loading... or something like that and then remove it when the data arrive.

    LazyTableImages does something like this.
  7. xingworld macrumors newbie

    Jan 24, 2011
    There is a sample named LazyTableImages in xcode help document.
    I think it's just what you wanted.

Share This Page