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 オブジェクト) へのポインターを渡します。そのようにした場合は、 NSValue* パラメータを取るように fetchDomainStatus を変更する必要があります。

于 2011-06-02T21:43:14.087 に答える