iOS 7 UINavigationController非平衡调用开始/结束外观转换

时间:2013-09-19 09:47:26

标签: ios uinavigationcontroller ios7

我正在使用以下代码在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

2 个答案:

答案 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)

希望你已经解决了这个问题。
1,我不认为使用@try @catch来确定推送或弹出是一个好主意 2,我在iOS7中也有过“不平衡的调用... blabla”的事情。我的情况,我需要强制旋转屏幕然后弹出到最后一个viewcontroller。在iOS 5或6中,只需强制旋转

-(void)viewWillDisappear
,它就能正常工作但iOS7崩溃了。所以在iOS7中我首先强制旋转然后弹出。
取决于此https://stackoverflow.com/a/17440074/1343200

  

“动画在最后一个相关动画未完成之前启动。”