0

I would like to add a completion callback on my method so that the progress of the HUD knows it is complete.

MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES]; hud.mode = MBProgressHUDModeAnnularDeterminate; hud.labelText = @"Loading"; [self doSomethingInBackgroundWithProgressCallback:^(float progress) { hud.progress = progress; } completionCallback:^{ [MBProgressHUD hideHUDForView:self.view animated:YES]; }]; 

What would I need to add to my method to confirm it is complete, or trigger this completionCallback from above?

In this case my method could be anything for example:

-(void)doSomethignInBackgroundWithProgressCallback { sleep(100); } 

1 Answer 1

3

In case of HUD you can use its delegate function hudWasHidden which will when you use HUD like this -

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

and if you want to know how to use callbacks in objective c then follow this post -

http://stackoverflow.com/questions/1015608/how-to-perform-callbacks-in-objective-c 

completion callback method -

- (void) doSomethingInBackground:(void (^) (void)) completion { // do your job here completion(); } 
Sign up to request clarification or add additional context in comments.

4 Comments

Using the showWhileExecuting does not increase the progress of the progress bar within the HUD though correct? Which I presume is what the callback part is for?
are you talking about HUD's progress view progress then you can increase the progress through showWhileExecuting.
yes if i only use the showWhileExecuting(method) then the progress for the AnnularDeterminate mode of HUD the progress bar in the HUD does not increase at all... I presumed using the above style with the Callback for completition would update the process.
are you able to help with the callback in the above code example for an example on this?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.