In my application, I have a UITableViewController.
Its View table is divided into 3 sections.
I download data for each of these sections from my server. For this, I have 3 functions (e.g. f1 f2 and f3). Each updates the corresponding NSArray used as the data source for my table.
Now I want to reload the data using these functions and update the TableView table after performing these 3 functions, but without disturbing the user.
I do not use asynchronous request, blocks, streams, etc., and I am looking for advice.
Actually, here is what I do:
-(void)viewDidLoad { //some settings [NSTimer scheduledTimerWithTimeInterval:15.0 target:self selector:@selector(reloadDatas) userInfo:nil repeats:YES]; dispatch_queue_t queue = dispatch_get_main_queue(); dispatch_async(queue, ^{ [self reloadDatas]; }); } -(void)reloadDatas { dispatch_queue_t concurrentQueue = dispatch_get_main_queue(); dispatch_async(concurrentQueue, ^{ [self f1]; [self f2]; [self f3]; [myDisplayedTable reloadData]; }); } -(void)f1 { //load datas with a url request and update array1 } -(void)f2 { //load datas with a url request and update array2 } -(void)f3 { //load datas with a url request and update array3 }
But here my tableView is “frozen” until it is updated.
I don't need the execution order of f1 f2 and f3, but I need to wait until these 3 functions are executed before updating my tableView.
Thank you for your help.
EDIT
Thanks for all your answers.
Here is a working solution:
As mros hints, I removed the send queue from viewDidLoad and replaced in reloadDatas:
dispatch_queue_t concurrentQueue = dispatch_get_main_queue();
from
dispatch_queue_t mainThreadQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
And finally, I reload the table into the main thread
dispatch_async(dispatch_get_main_queue(), ^{ [myDisplayedTable reloadData]; });