1

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.

Grauzten
  • 353
  • 5
  • 19
  • ***Just bloody move your synchronous network operations to a background thread.*** –  Oct 04 '12 at 05:21
  • What @H2CO3 said, probably, but it is hard to tell without seeing any of your code. – jrturton Oct 04 '12 at 06:11
  • @H2CO3 those were already in a separate thread. Kindly see edited post. – Grauzten Oct 05 '12 at 01:59
  • But, is your "other separate thread" running in the background, or on the main thread? It sounds as if it is running on the main thread. – lnafziger Oct 05 '12 at 02:25
  • @lnafziger I did another thread through this `dispatch_queue_t fetchQ = dispatch_queue_create("iMonggo All Items Fetcher", NULL);` and `dispatch_sync(fetchQ, ^{ });` and it's running in the background – Grauzten Oct 05 '12 at 02:35
  • dispatch_sync runs on the current thread, which I'm assuming is your main thread? – lnafziger Oct 05 '12 at 13:38

0 Answers0