ASIHTTPRequest startSynchronous callback not showing/hiding MBProgressHUD before/after data is received
I'm trying to simply create a MBProgressHUD, show it, start a synch or asynch request, push a new controller on UINavigationController, and remove said MBProgressHUD. However, the HUD does not appear until the data is received. There is only a flicker of the HUD. I tried doing this asynchronously, but that did the exact same thing. Any ideas?
ASIFormDataRequest* request = [ASIFormDataRequest requestWithURL:url];
[request setPostValue:@"occ_get_images_by_tag" forKey:@"action"];
[request setPostValue:[NSString stringWithFormat:@"%@", tag_id] forKey:@"tag_id"];
//HUD is a property of the UIViewController
HUD = [[MBProgressHUD alloc] initWithView:self.view];
[self.view addSubview:HUD];
HUD.delegate = self;
//Tried messing with this, making a message and changing onTarget: to self
//didn't work
[HUD showWhileExecuting:@selector(startSynchronous) onTarget:request withObject:nil animated:YES];
[request startSynchronous];
NSError* error = [request error];
if(!error){
NSArray* tempArr = [[request responseString] objectFromJSONString];
// Do some stuff
开发者_开发问答[self.navigationController pushViewController:imtv animated:YES];
[HUD removeFromSuperview];
}else{
NSLog(@"%@", [error description]);
}
My understanding of how ASIHTTPRequest works is that things that happen before startSynchronous will actually happen before that message is called. Then, anything inside the if(!error) will happen after data is received and ready to be processed. It just seems like the callback isn't working at all.
Also if it's of any help, this all happens in tableView:didSelectRowAtIndexPath:.
You will not be able to use MBProgressHUD on the main thread of the application. If you want to get this working in your sample code, use the delegates of the ASIHTTPRequest and you will be able to see the MBProgressHUD
精彩评论