Currently, I'm downloading data from a web server by calling a method fetchProducts
. This is done in another separate thread. As I successfully download fifty items inside the method stated above, I post
a notification to the [NSNotification defaultCenter]
through the method call postNotificationName: object:
which is being listened to by the Observer
. Take note that this Observer
is another ViewController
with the selector updateProductsBeingDownloadedCount:
. Now as the Observer
gets the notification, I set the property of my progressView
and a label that tells the progress. Below is the code I do this change in UI.
dispatch_async(dispatch_get_main_queue(), ^{
if ([notif.name isEqualToString:@"DownloadingProducts"]) {
[self.progressBar setProgress:self.progress animated:YES];
NSLog(@"SetupStore: progress bar value is %.0f", self.progressBar.progress);
self.progressLabel.text = [NSString stringWithFormat:@"Downloading %.0f%% done...", self.progress * 100];
NSLog(@"SetupStore: progress label value is %@", self.progressLabel.text);
[self.view reloadInputViews];
}
});
The idea is to move the progressView
simultaneously as more items were being downloaded until it is finished. In my case, the progressView
's animation will just start right after the items were already downloaded, hence a delay. Kindly enlighten me on this.