at some point in my apps, i put a list of code that requires the app to get data from server, knowing this process might takes quite some time, i decide to put a loading notification where the screen darken and i put a label in the center of it saying “now loading blablabla data from server”
the problem is, in between loading several data from server (JSON data), the label won’t change even if i put the code to change it between the JSON function
here is my code
[self.viewReportProduksi getDataReport];
[loadinglabel setText:@"Loading Chart Data from server . . ."];
[self.viewReportProduksi getChartData];
[loadinglabel setText:@"Loading Data Komisi from server . . ."];
[self.viewKomisi getDataKomisi];
[loadinglabel setText:@"Loading Bonus Data from server . . ."];
[self.viewBonus getDataBonus];
[loadinglabel setText:@"Loading Bonus Agen Data from server . . ."];
[self.viewBonusAgen getDataBonusAgen];
[loadinglabel setText:@"Loading Agent Reward Data from server . . ."];
[self.viewAgenReward getDataRewardAgen];
those “getXXXXXX” is a method where the JSON is executed.
logically this should make the app show how far have the progress gone. but the label keep stucked at “loading chart data from server” and wont change accordingly to what i code.
i have tried this on both main thread and using dispatch_queue, both shows no differences
thanks
The problem is that all the graphics updates happen on the main thread. So nothing will change on the display untile the whole of your block of code is complete. I think this is a case where you need to do all the data loading in the background. For maximum flexibility, I would use a load of NSBlockOperations.
First you need a method to run on the main thread to update your status text.
Then, instead of your method sequentially loading all the data, create an NSBlockOperation for each phase and bung it on an operation queue.
Because each operation has a dependency on the previous operation, they will be executed one after the other, but on some background thread. Using operations and operation queues has an advantage over GCD because
-addDependency:operations have a built in mechanism for cancellation. If the user decides to quit the app halfway through, you can issue
All operations on the queue that haven’t been started will be cancelled.