开发者

have MBProgressHUD call a method that returns a value

开发者 https://www.devze.com 2023-03-09 22:19 出处:网络
I would like to use MBProgressHUD with... [HUD showWhileExecuting:@selector(fetchDomainStatus) onTarget:self withObject:nil animated:YES];

I would like to use MBProgressHUD with...

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

but I need to call a method (fetchDomai开发者_开发问答nStatus) that returns the domainStatus (an int).

How can I do that without somekind of class variable?


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];
    });
});


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消