I’m downloading data from the web that is then showed on a UITableView. Because I want a responsive UI I’m using background downloading with GCD. So while the data is downloading there is an empty UITableView displaying (which is not so pretty). And over that there is a UIActivtyIndicatorView (setup in IB) spinning.
What I would like is to instead of showing a empty table to display a gray screen with the UIActivityIndicatorView over it.
The code I have so far is this:
dispatch_async(dispatch_get_global_queue(0, 0), ^{
NSArray *downloadedCareerIds = [CareersParser idsFrom:@"web"];
NSArray *diskCareerIds = [CareersParser idsFrom:@"disk"];
BOOL equalIds = [downloadedCareerIds isEqualToArray:diskCareerIds];
if (!equalIds) {
DLog(@"ids not equal");
dispatch_async(dispatch_get_main_queue(), ^{
/* Send UI updates back to the main thread. */
// I think here would be a good idead to insert the gray view over the table
[loadingIndicator startAnimating];
// Do GUI stuff on the main thread ...
[loadingIndicator stopAnimating];
// Remove the gray view?
});
}
});
Just make a gray view with the bounds of the UITableView, and add it as a subview of the tableView. Remove the gray view once you’ve finished loading.