我正在使用以下代码在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
答案 0 :(得分:1)
我承认使用try和catch不是一个好习惯。由于问题与ViewDeck有关,所以我只需简单地替换centerViewController,并避免UINavigationController的推送弹出堆栈错误。
这是代码。希望它可以帮助别人。
-(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;
}
}
答案 1 :(得分:0)
-(void)viewWillDisappear
,它就能正常工作但iOS7崩溃了。所以在iOS7中我首先强制旋转然后弹出。
“动画在最后一个相关动画未完成之前启动。”