這是一個混合MBProgressHUD和ASI的示例。
這個想法是在開始請求之前開始更新,然後在完成塊或失敗塊中結束更新。
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
hud.labelText = @"Updating…";
NSURL *url = [NSURL URLWithString:@"http://allseeing-i.com"];
__block ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setCompletionBlock:^{
[MBProgressHUD hideHUDForView:self.view animated:YES];
// Use when fetching text data
NSString *responseString = [request responseString];
// Use when fetching binary data
NSData *responseData = [request responseData];
}];
[request setFailedBlock:^{
[MBProgressHUD hideHUDForView:self.view animated:YES];
NSError *error = [request error];
}];
[request startAsynchronous];
謝謝:-)這是凌晨1點,當我發佈這個問題,因此回覆晚:-) –