我正在使用以下代码在 ViewDeck 中切换视图,当我尝试弹出到现有视图时,它在 iOS5 和 6 但 7 中完全没问题。屏幕变成全白/黑。
-(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];
});
}
}
}
}
}
我确实尝试添加延迟 0.1,但这无济于事。从控制台,我发现它同时弹出了两个 VC。
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