MegaManX
MegaManX

Reputation: 8948

How to chain several actions using MBProgressHUD?

Basically I have 3 steps:

  1. I need to prepare the data to be sent to the server. This takes some time.
  2. After preparing the data, I have to send it to the server - this also takes a while.
  3. I wait for the response from server that everything is OK.

I was thinking of using MBProgressHUD for each of these actions - I show hud, and use the showWhileExecuting method. Then when I hide hud in that code I call the next action, and show hud again.

In theory this should work, but is this the way this should be done?

Upvotes: 1

Views: 347

Answers (2)

Dhaval
Dhaval

Reputation: 215

i get the frist Action at button clicked,i use this :

    HUD = [[MBProgressHUD alloc] initWithWindow:[UIApplication sharedApplication].keyWindow];

        [self.view.window addSubview:HUD];


        // Regiser for HUD callbacks so we can remove it from the window at the right time
        HUD.delegate = self;

        // Show the HUD while the provided method executes in a new thread
        [HUD showWhileExecuting:@selector(DNS_info) onTarget:self withObject:nil animated:YES];

and then 2 button clicked , get the action ,like this :

HUD = [[MBProgressHUD alloc] initWithWindow:[UIApplication sharedApplication].keyWindow];

        [self.view.window addSubview:HUD];
//        HUD.dimBackground = NO;

        // Regiser for HUD callbacks so we can remove it from the window at the right time
        HUD.delegate = self;

        // Show the HUD while the provided method executes in a new thread
        [HUD showWhileExecuting:@selector(whois) onTarget:self withObject:nil animated:YES];

i think, this is help to you.

Upvotes: 1

Yorxxx
Yorxxx

Reputation: 679

It would be better to not depend on MBProgressHUD. You should use it as a feedback element for the user, not as an operation manager.

You could use a NSOperationQueue, for example, and just notify the hud to update its data/status in each iteration.

Of course, you could use it like you said, but does not seems clean to me (programatically).

Upvotes: 2

Related Questions