TableView reloaddata after UI shows up

Discussion in 'iOS Programming' started by temm, May 28, 2010.

  1. temm macrumors newbie

    May 19, 2009

    I have tabbar app where the second tab has a tableViewController.
    When on the first tab i select the second tab the tableview shows up and all data is loaded.

    The problem is, that the data is from the network and it takes 2-3 seconds to load. Until the data is loaded the UI of the tableview is not showen until all data is loaded.

    How can i show the second tab with no data in the tableview and then reload the table data?

    I've tried to use -viewWillAppear and -viewDidAppear but the UI is not showen until they both completely finish.

    This is what i've tried

    - (void)viewWillAppear:(BOOL)animated {
    	dataArray = [[NSArray alloc] initWithObjects:@"", nil];
    	[self.tableView reloadData];
    	[super viewWillAppear:animated];
     - (void)viewDidAppear:(BOOL)animated {
            [self loadData]; //This will load the actual data into dataArray
    	[self.tableView reloadData];
            [super viewDidAppear:animated];

  2. TiberiusXavier macrumors member

    Apr 18, 2010
    How are you loading the data? Based on your statements, it sounds like you are doing this synchronously and overloading the methods that would give responsiveness to the UI. If you are doing it asynchronously, you can make the call and let the delegate callbacks update the table when the data is loaded.

    So how exactly do you do loadData? Are you using NSURLConnection? Are you trying to use something like NSArray:: + (id)arrayWithContentsOfURL:(NSURL *)aURL?
  3. temm thread starter macrumors newbie

    May 19, 2009
    I'm using a tcp socket and adding objects to an NSArray
  4. PhoneyDeveloper macrumors 68040


    Sep 2, 2008

Share This Page