MBProgressHUD を使用したい...
[HUD showWhileExecuting:@selector(fetchDomainStatus) onTarget:self withObject:nil animated:YES];
しかし、domainStatus (int) を返すメソッド (fetchDomainStatus) を呼び出す必要があります。
ある種のクラス変数なしでどうすればそれを行うことができますか?
MBProgressHUD を使用したい...
[HUD showWhileExecuting:@selector(fetchDomainStatus) onTarget:self withObject:nil animated:YES];
しかし、domainStatus (int) を返すメソッド (fetchDomainStatus) を呼び出す必要があります。
ある種のクラス変数なしでどうすればそれを行うことができますか?
ブロックを使用できる場合 (つまり、アプリが 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];
});
});
おそらくあなたがやりたいことはこれです:
[HUD show:YES];
int status = [self fetchDomainStatus];
[HUD hide:YES];
それ以外の場合は、「withObject」パラメーターを使用して、戻り値を格納できるオブジェクト (おそらく NSValue オブジェクト) へのポインターを渡します。そのようにした場合は、 NSValue* パラメータを取るように fetchDomainStatus を変更する必要があります。