1

I would like to use MBProgressHUD with...

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

but I need to call a method (fetchDomainStatus) that returns the domainStatus (an int).

How can I do that without somekind of class variable?

mputnamtennessee
  • 372
  • 4
  • 14

2 Answers2

1

If you can use blocks (i.e., your app is iOS 4.0+) you can do something like this, and still have all threading magic preserved:

MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];

dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
    // Do the task in the background
    int status = [self fetchDomainStatus];
    // Hide the HUD in the main tread 
    dispatch_async(dispatch_get_main_queue(), ^{
        [MBProgressHUD hideHUDForView:self.view animated:YES];
    });
});
Matej Bukovinski
  • 6,152
  • 1
  • 36
  • 36
0

Probably what you want to do is this:

[HUD show:YES];
int status = [self fetchDomainStatus];
[HUD hide:YES];

Otherwise, use the "withObject" parameter to pass in a pointer to an object (probably an NSValue object) where you can store the return value. You'd have to modify fetchDomainStatus to take an NSValue* parameter if you did it like that.

Steve N
  • 2,667
  • 3
  • 30
  • 37