0

I'm using AFnetworking to make a call to a server. While downloading I am using MBProgressHUD to show that data is being downloaded. So far everything works great. My issue is when I press the home button and then relaunch the app. I would like for the page to automatically refresh itself and for MBProgressHUD to display to the user that something is being downloaded. That I cannot do. I can download the data, but I cannot get the HUD part to work.

First, in the viewDidLoad Method I add this:

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(applicationDidBecomeActiveNotificationAction)
                                             name:UIApplicationDidBecomeActiveNotification
                                           object:nil];

Now in the method applicationDidBecomeActiveNotificationAction, I call [self downloadWebsites].

In the method downloadWebsites is where the bulk of the work is done: Here it is:

//show the hud
MBProgressHUD* progressHUD = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
progressHUD.labelText = @"Loading";
progressHUD.mode = MBProgressHUDAnimationFade;

[self.list_websites getPath:[NSString stringWithFormat:@"%@?%@", @"websites", self.auth_header] parameters: nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
    //download data in the success block
    //refresh the ui
    [self.tableView reloadData];
    [progressHud self.view animated:YES];
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    //failure block. log the error
    NSLog([error description]);

}];

Why doesn't this work? I can get the data. But I can't get the progressHud to display. How do I fix this?

Stunner
  • 12,025
  • 12
  • 86
  • 145
user678392
  • 1,981
  • 3
  • 28
  • 50
  • Can you try to put the codes to show the progressHUD to be run in the main thread? – Valent Richie Jun 29 '13 at 14:27
  • @ verbumdei isn't the line "MBProgressHUD* progressHUD = [MBProgressHUD showHUDAddedTo:self.view animated:YES];" being run on the main thread? Maybe I'm not understanding your question ... – user678392 Jun 30 '13 at 18:06
  • Can you print some logs to confirm that you are indeed successfully getting the data? Also this line: `[progressHud self.view animated:YES];` doen't make sense. – Stunner Jul 03 '13 at 03:06
  • I know that I have gotten the data. I have just decided to dump mbprogress hud except in a few situations. – user678392 Jul 07 '13 at 18:03

1 Answers1

0

The Notification Runloop and the HTTP request runloop maybe not the same. So method that show a progress HUD maybe not called.

lynulzy
  • 561
  • 7
  • 19