I am using the following code to switch views in ViewDeck, it was completely fine in iOS5 and 6 but 7, when I try to pop to an exist view. The screen became all white/black.
-(void)switchViewWithViewController:(UIViewController*)viewControllerToSwitch
{
if (viewControllerToSwitch)
{
// Reset Menu Button
[self.viewDeckController closeLeftViewAnimated:YES completion:^(IIViewDeckController *controller)
{
[((BaseViewController*)viewControllerToSwitch) closeMenu];
}];
@try
{
[((UINavigationController*)self.viewDeckController.centerController) pushViewController:viewControllerToSwitch animated:NO];
}
@catch (NSException * ex)
{
//“Pushing the same view controller instance more than once is not supported”
NSRange range = [ex.reason rangeOfString:@"Pushing the same view controller instance more than once is not supported"];
if([ex.name isEqualToString:@"NSInvalidArgumentException"] && range.location != NSNotFound)
{
//view controller already exists in the stack - just pop back to it
if (!IS_IOS7)
{
[((UINavigationController*)self.viewDeckController.centerController) popToViewController:viewControllerToSwitch animated:NO];
}
else
{
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void)
{
[((UINavigationController*)self.viewDeckController.centerController) popToViewController:viewControllerToSwitch animated:NO];
});
}
}
}
}
}
I did try to add a delay 0.1 but it is not going to help. From the console, I found that it was popping two VCs at the same time.
Unbalanced calls to begin/end appearance transitions for <GameViewController: 0x15ef5630>.
-[BaseViewController viewDidAppear:] [Line 49] VC is showing: GameViewController
-[BaseViewController viewDidAppear:] [Line 49] VC is showing: HomePageViewController
I admit that using try and catch is not a good practice. As the question is regarding to ViewDeck, so I just simply replace the centerViewController on the fly, and avoid the push pop stack error from UINavigationController.
Here is the code. Hope it can help someone.
-(void)switchViewWithViewController:(BaseViewController*)viewControllerToSwitch
{
if (viewControllerToSwitch)
{
// Reset Menu Button
[self.viewDeckController closeLeftViewAnimated:YES completion:^(IIViewDeckController *controller)
{
[viewControllerToSwitch closeMenu];
}];
UINavigationController *navVC = [[UINavigationController alloc] initWithRootViewController:viewControllerToSwitch];
self.viewDeckController.centerController = navVC;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With