我想用MBProgressHUD與...有MBProgressHUD調用返回的值
[HUD showWhileExecuting:@selector(fetchDomainStatus) onTarget:self withObject:nil animated:YES];
的方法,但我需要調用返回的domainStatus(一個int)的方法(fetchDomainStatus)。
我該怎麼做,沒有一些類變量?
我想用MBProgressHUD與...有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對象),可存儲返回值。如果你這樣做了,你必須修改fetchDomainStatus來取一個NSValue *參數。
你的回答是正確的標記。謝謝! – mputnamtennessee 2011-07-20 12:10:37