Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7656775
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T12:51:14+00:00 2026-05-31T12:51:14+00:00

I’m using MBProgressHUD in our teaching App, which is tab bar navigated. The user

  • 0

I’m using MBProgressHUD in our teaching App, which is tab bar navigated.

The user will come from a tableview via Urban Airship’s storefront directly to the UA detail view.
Once buy is clicked I bring on HUD with

 HUD = [[MBProgressHUD alloc] initWithWindow:[UIApplication sharedApplication].keyWindow];
 [self.view.window addSubview:HUD];

It is using the showWhileExecuting statement.

It goes through three while statements to change from “Connecting” to “Downloading” to “Unpacking”.
All working perfectly OK.

Here comes the problem…
The second time I do this the label text will not change. It is stuck on “Connecting”.
I can see in the NSLog that it is going through the other loops.
On top of that, if I try to change the Mode, the app crashes.

This only happens the second time, and any subsequent uses. If I kill the App everything works again for the first time.

Looks to me that MBProgressHUD doesn’t get reset when it’s finished.
(ARC is used in the project)

Anyone with a solution?
Thanks

Edit:

- (void)showWithLabelDeterminate 
{

    HUD = [[MBProgressHUD alloc] initWithWindow:[UIApplication sharedApplication].keyWindow];
    HUD.mode = MBProgressHUDModeIndeterminate;
    [self.view.window addSubview:HUD];


    HUD.delegate = self;
    HUD.labelText = NSLocalizedString(@"Connecting","");
    HUD.detailsLabelText = @" ";
    HUD.minSize = CGSizeMake(145.f, 145.f);
    HUD.dimBackground = YES;

    [HUD showWhileExecuting:@selector(lessonDownloadProgress) onTarget:self withObject:nil animated:YES];
}


-(void)lessonDownloadProgress
{

    DataManager *sharedManager = [DataManager sharedManager];
    //  HUD.mode = MBProgressHUDModeIndeterminate;
    HUD.labelText = nil;
    HUD.detailsLabelText = nil;

    while ([sharedManager.downHUD floatValue] == 0.0f) 
    { 
        [self parentViewController];
        NSLog(@"HUD lessonDownloadProgress: %f", HUD.progress);
        HUD.labelText = NSLocalizedString(@"Connecting","");
        HUD.detailsLabelText = @" ";
        NSLog(@"Waiting for download to start");
        //  Wait for download to start
        usleep(80000);
    }

    // Switch to determinate mode     
    // HUD.mode = MBProgressHUDModeDeterminate;
    HUD.labelText = NSLocalizedString(@"DownLoading","");
    HUD.progress = [sharedManager.downHUD floatValue];

    while (HUD.progress < 1.0f && [sharedManager.cleanedUp isEqualToString:@"No"])
    {
        //  [self parentViewController];
        HUD.labelText = NSLocalizedString(@"Downloading","");
        NSLog(@"HUD lessonDownloadProgress: %f", HUD.progress);
        HUD.progress = [sharedManager.downHUD floatValue];                       
        NSString *percent = [NSString stringWithFormat:@"%.0f", HUD.progress/1*100];
        HUD.detailsLabelText = [percent stringByAppendingString:@"%"];
        usleep(50000);
    }

    //  Switch HUD while cleanUp
    HUD.mode = MBProgressHUDModeIndeterminate;

    while ([sharedManager.cleanedUp isEqualToString:@"No"]) 
    {
        [self parentViewController];
        HUD.labelText = NSLocalizedString(@"Unpacking","");
        HUD.detailsLabelText = @" ";
        //  wait for cleanup
        NSLog(@"Waiting for clean up");
        usleep(50000);
    }

    NSLog(@"++ Finished loops ++");
    NSLog(@"Finished HUD lessonDownloadProgress: %f", HUD.progress);

    [MBProgressHUD hideHUDForView:self.view animated:YES];
    [HUD removeFromSuperview];
    HUD.delegate = nil;

    [HUD release];
    HUD = nil;

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T12:51:15+00:00Added an answer on May 31, 2026 at 12:51 pm

    I cannot spot the issue in the code you posted; but some refactoring might help.

    Rather than polling the DataManager you could use KVO to observe properties on the DataManager and respond to those changes. (“Don’t call us; we’ll call you.) So here’s a suggested approach if you want.

    Your class interface:

    @interface YourClass : UIViewController    // or whatever your superclass is...
    {
        MBProgressHUD *_hud;
        DataManager *_dataManager;
    
        //  your other ivars
    }
    @end
    

    And in your implementation file…

    @interface YourClass()
    @property (nonatomic, retain) DataManager dataManager;
    @end
    

    Above I’ve declared your dataManager as a property so that we can observe it.

    To start the download process we now have a method downloadLesson:

    - (void)downloadLesson;
    {
        //  show HUD and retain it (showHUDAddedTo:animated: returns autoreleased object)
        MBProgressHUD *HUD = [MBProgressHUD showHUDAddedTo:self.view animated:YES] retain];
    
        //  observe properties on the dataManager
        [self addObserver:self forKeyPath:@"dataManager.progress" options:NSKeyValueObservingOptionNew context:nil];
        [self addObserver:self forKeyPath:@"dataManager.cleanedUp" options:NSKeyValueObservingOptionNew context:nil];
        [self addObserver:self forKeyPath:@"dataManager.downHUD" options:NSKeyValueObservingOptionNew context:nil];
    
        //  begin your download here...
    
        HUD.labelText = NSLocalizedString(@"Connecting", "");
        HUD.detailsLabelText = @" ";
        HUD.progress = self.dataManager.downHUD;
    }
    

    Now use KVO to update the appearance of the HUD:

    - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context;
    {
        if( [keyPath isEqualToString:@"dataManager.cleanedUp"] )
        {
            if( [[[self dataManager] cleanedUp] isEqualToString:@"Yes"] )
            {
                [MBProgressHUD hideHUDForView:[[UIApplication sharedApplication] keyWindow] animated:YES];
                [HUD release];  HUD = nil;
                [self removeObserver:self forKeyPath:@"dataManager.progress"];
                [self removeObserver:self forKeyPath:@"dataManager.cleanedUp"];
                [self removeObserver:self forKeyPath:@"dataManager.downHUD"];
            }
        }
        if( [keyPath isEqualToString:@"dataManager.downHUD"] )
        {
            //  if the data manager updates progress, update our HUD
            HUD.progress = self.dataManager.downHUD;
            if( self.dataManager.downHUD == 0.0 )
                //  no progress; we're just connecting
                HUD.labelText = NSLocalizedString(@"Connecting", "");
            else if( self.dataManager.downHUD < 1.0 )
            {
                //  progress >0.0 and < 1.0; we're downloading
                HUD.labelText = NSLocalizedString(@"Downloading", "");
                NSString *percent = [NSString stringWithFormat:@"%.0f%%", HUD.progress/1*100];
                HUD.detailsLabelText = percent;
            }
            else
            {
                //  progress == 1.0, but we haven't cleaned up, so unpacking
                if( [[[self dataManager] cleanedUp] isEqualToString:@"No"] )
                {
                    HUD.labelText = NSLocalizedString(@"Unpacking","");
                    HUD.detailLabelsText = @" ";
                }
            }
        }
    }
    

    Alternatively, you could use notifications to do the updates, wherein the DataManager posts NSNotifications for which your view controller is registered. Or, if you were open to refactoring the DataManager you could use blocks to do the updates. All of these solutions avoid having to explicitly block your thread to poll the DataManager. Hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We're building an app, our first using Rails 3, and we're having to build
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have a text area in my form which accepts all possible characters from
I am using Paperclip to handle profile photo uploads in my app. They upload
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.