0

I have a method refreshDataAction:

- (void)refreshDataAction
{
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    hud.labelText = @"Loading Data.Please Wait";
    [self deletePreviousValues];
    dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
        NSLog(@"Getting customer values");
        [self getAllCustomerValues];
        NSLog(@"Got customer values");

        NSError *nwerror = nil;
        if (![self.secondMOC save:&nwerror])
        {
            NSLog(@"209 Failed to save second MOC");
        }
        else
        {
            //NSLog(@"saved success");
        }
        dispatch_async(dispatch_get_main_queue(), ^{
            [MBProgressHUD hideHUDForView:self.view animated:YES];
        });
        NSLog(@"Saved");
    });

    NSLog(@"Dispatched");   
}

So as soon as the refreshDataAction starts i should see the HUD. But no its like waiting for 13 seconds before showing the HUD. I have no idea why it is happening like that. I tried different one like ActivityIndicator, but to no avail. Why is my app waiting 13 seconds to start the hud. On simulator its instant. I click button and i see HUD. But on the device 13 second delay. Start the hud immediately while background thread is doing some work. Please help. Spent the entire 5 hours figuring out ways to do this task.

There is my question here :UIAlertview hanging while the thread in background is loading data

I changed it to MBProgressHUD. May be some developers who have worked with MBProgressHUD could see this problem.

Is my main UI thread in some sort sleep mode for 13 seconds? I really dont know at this point. FYI, it's in iOS 6.0. This is an in-house iPad app. If you need more info, do ask.Thanks

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
RookieAppler
  • 1,517
  • 5
  • 22
  • 58
  • Why did you create a duplicate of your earlier question? All you have done is replaced the alert view with `MBProgressHUD`. Neither is the cause of the problem. – rmaddy Feb 21 '13 at 22:55
  • possible duplicate of [UIAlertview hanging while the thread in background is loading data](http://stackoverflow.com/questions/15010458/uialertview-hanging-while-the-thread-in-background-is-loading-data) – rmaddy Feb 21 '13 at 22:55

1 Answers1

0

I'd add the following to your viewDidLoad.

HUD = [[MBProgressHUD alloc] initWithView:self.navigationController.view];
[self.navigationController.view addSubview:HUD];
HUD.delegate = self;
HUD.labelText = @"";
HUD.mode = MBProgressHUDModeIndeterminate;

Then you can simply call the following methods without the dispatch_get_main_queue().

[HUD show:YES];

and...

[HUD hide:YES];
AndyDev
  • 1,409
  • 10
  • 17