In this project, I am using a MBProgressHUD when I get JSON content from a server. The first time I start my app, the animation from my MenuViewController to my Page works fine. But when I go back to my Menu and to the Page again, no viewcontroller switch animation is shown. It only happens when I add the MBProgressHUD functionality..
My Page ViewDidLoad method:
- (void)viewDidLoad
{
[super viewDidLoad];
HUD = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
[self performSelectorInBackground:@selector(loadPage) withObject:nil];
}
The loadPage method, simplified:
-(void) loadPage {
//loading functionality, deleted for now.
dispatch_async(dispatch_get_main_queue(), ^{
[_lblTitle setText: [postsArray[0] objectForKey:@"title"]];
[_webview loadHTMLString:[postsArray[0] objectForKey:@"content"] baseURL:nil];
[HUD hide:YES];
});
}
So when I delete the 2nd and 3rth line in viewDidLoad and the HUD hide, the animation works fine every time. What am I doing wrong?
Replace
HUD = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
[self performSelectorInBackground:@selector(loadPage) withObject:nil];
with
MBProgressHUD *searchHUD = [[MBProgressHUD alloc] initWithView:self.view];
searchHUD.dimBackground=YES;
searchHUD.animationType = MBProgressHUDAnimationZoom;
[self.view addSubview:searchHUD];
[searchHUD showWhileExecuting:@selector(loadPage) onTarget:self withObject:Nil animated:YES];
Reason: MBProgressHud provides this functionality to run any method in background thread..