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);
}    
StuartM
  • 6,743
  • 18
  • 84
  • 160

1 Answers1

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();
}
saadnib
  • 11,145
  • 2
  • 33
  • 54
  • 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? – StuartM Aug 30 '12 at 13:58
  • are you talking about HUD's progress view progress then you can increase the progress through showWhileExecuting. – saadnib Aug 30 '12 at 14:02
  • 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. – StuartM Aug 30 '12 at 14:09
  • are you able to help with the callback in the above code example for an example on this? – StuartM Aug 30 '12 at 17:01