0

I'm using MDProgressHUD to manage the progress of my downloads which uses NSConnection. Everything is working great. I'm having an issue when I try to change the HUD labelText from saying Downloading to Finishing Up when connectionDidFinishLoading is called.

In my connectionDidFinishLoading method I'm changing the labelText and changing the icon to a checkmark , like in the example app.

    HUD.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"37x-Checkmark.png"]];
HUD.mode = MBProgressHUDModeCustomView;
HUD.labelText = @"Finishing Up";
NSLog(@"show change now!!!");

Right after that code I unzip the download and do some db manipulation.

But for some reason it doesn't change until the end of the function is reached where [HUD hide:YES afterDelay:4]; is called.

I would like it to change before it starts to unzip my contents because the download is full and it makes the app look like its hanging or frozen.

I'm using zipArchive to do the extraction if it matters.

Any advice would be appreciated.

user1086377
  • 328
  • 5
  • 16
  • It appears that the mod is only changing when [HUD hide:YES afterDelay:2] is called. But in the docs it says that setting the mode should be thread safe. I wonder if running it with show while executing will work. – user1086377 Apr 27 '12 at 17:38
  • using showWhileExucuting didn't work either. this time the hud disappears and I can't get it to show back up. – user1086377 Apr 27 '12 at 18:30

5 Answers5

2

This worked for me

dispatch_async(dispatch_get_main_queue(), ^{
  progressView.titleLabelText = @"Downloading ...";
});
0

Did you try with:

[HUD setNeedsLayout];
[HUD setNeedsDisplay];
Jonathan Naguin
  • 14,526
  • 6
  • 46
  • 75
0

MBProgressHUD uses KVO for detecting changes to properties like labels, progress, etc. As soon as you change it observeValueForKeyPath() should run and update the UI. Is there any chance that your code is really intensive and is blocking the UI? I've seen that happen before..

Brian Antonelli
  • 736
  • 9
  • 16
0

You should just add this method to the header file of MBProgressHud:

+ (MB_INSTANCETYPE)showHUDAddedTo:(UIView *)view withText:(NSString *)text;

And implement it in the .m file as follows:

+ (MB_INSTANCETYPE)showHUDAddedTo:(UIView *)view withText:(NSString *)text
{
    MBProgressHUD *hud = [[self alloc] initWithView:view];
    hud.labelText = text;
    [view addSubview:hud];
    [hud show:YES];
    return MB_AUTORELEASE(hud);
}

and call it wherever you want like:

[MBProgressHUD showHUDAddedTo:self.view withText:@"Loading..."];
jhurray
  • 81
  • 4
  • So If I have added the HUD once and want t change the text only (without hiding and showing it again) then how to do that? – Ans Jun 07 '14 at 09:21
  • 1
    simply get the hud from view and change the labelText property – jhurray Jun 16 '14 at 22:56
0

For anyone else coming back to this, note that setting:

HUD.hidden = YES;

is not sufficient for the delegate method to be called. You must actually call:

[HUD hide:YES];
thesimm
  • 774
  • 3
  • 12