1

我想将 MBProgressHUD 与...一起使用

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

但我需要调用一个返回 domainStatus(一个 int)的方法(fetchDomainStatus)。

如果没有某种类变量,我怎么能做到这一点?

4

2 回答 2

1

如果您可以使用块(即,您的应用程序是 iOS 4.0+),您可以执行以下操作,并且仍然保留所有线程魔法:

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];
    });
});
于 2011-06-21T10:42:42.067 回答
0

可能您想要做的是:

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

否则,使用“withObject”参数传入指向可以存储返回值的对象(可能是 NSValue 对象)的指针。如果您这样做,则必须修改 fetchDomainStatus 以采用 NSValue* 参数。

于 2011-06-02T21:43:14.087 回答