Mar 30

Yesterday I ran into an issue where a UITableView would not display until some remote data was loaded into a local array, even though I was loading this data in a seperate thread.

- (void)viewDidAppear:(BOOL)animated {
        [self doInitialLoad];
}
- (void)doInitialLoad {
        [self showActivityViewer]; // shows a screen activity indicator overlay
        [self laadJSONTabel]; // loads the actual data into the tableview
        [self.recentTable reloadData]; // reloads the tableview so data shows up
        [self hideActivityViewer]; // hides the activity indicator overlay
}

It turns out that visual stuff gets queued to the end run of the loop, this resulted in a very sloppy interface which would react very slow to a change to another UIViewController due to remote data being downloaded first.

An easy fix for this, is using a performSelector on the function with a 0.0 delay, that will give it a zero delay but move loading the data to the next run-loop so all other stuff gets properly executed first. This results in an interface which feels a lot snappier and a proper UIActivityIndicatorView being displayed on screen while the data is loading:

- (void)viewWillAppear:(BOOL)animated {
        [self showActivityViewer];
}
- (void)viewDidAppear:(BOOL)animated {
        [self performSelector:@selector(doInitialLoad) withObject:NULL afterDelay:0.0];

}
- (void)doInitialLoad {
        [self laadJSONTabel];
        [self.recentTable reloadData];
        [self hideActivityViewer];
}

Leave a Reply

preload preload preload