Search code examples
iosobjective-cmbprogresshud

MBProgressHUD fades / lightens when triggered by this button


What is going on here?

http://screencast.com/t/WACeaQP00iqb

Here's the code for that button (the three method calls spawn 3 (yes 3; i didn't write the server :D) asynchronous data tasks that take some time to finish):

- (IBAction)didTouchClockButton:(id)sender {
[self.dr isUserClockedIn];

hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
hud.dimBackground = NO;

// hail mary
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate distantPast]];

dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
    // Do something...
    if (![self.dr isNetworkDead])
        if ([self.dr isUserClockedIn]) { // add clock in / clock out function to this button
            hud.labelText = @"Clocking Out..";
            [self.dr clockOut];
        } else {
            hud.labelText = @"Clocking In..";
            [self.dr clockIn];
        }  

});

}

I put the hud dismissal inside a KVO callback, which isn't working yet but first things first.


Solution

  • I ended up dismissing the HUD the line before I call the method that updates the other view elements. Right now they're both happening near instantaneously so it's fine, although if the view was still updating after the HUD went down that would be lame. So the solution is to not mess with the view while your HUD is active. A messy solution, so if anyone has a better one I'm all ears.