Wait until data is loaded from a server with json

Discussion in 'iPhone/iPad Programming' started by Mac2011, Jan 28, 2011.

  1. macrumors newbie

    Joined:
    Jan 11, 2011
    #1
    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. macrumors G4

    Joined:
    Jan 5, 2006
    Location:
    Redondo Beach, California
    #2
    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. thread starter macrumors newbie

    Joined:
    Jan 11, 2011
    #3
    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. macrumors 6502

    Joined:
    Aug 29, 2010
    #4
    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:

    Code:
    [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.

    http://developer.apple.com/library/...ce/UITableView_Class/Reference/Reference.html
     
  5. thread starter macrumors newbie

    Joined:
    Jan 11, 2011
    #5
    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. macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #6
    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. macrumors newbie

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

Share This Page