应用程序在ContainerView中切换ViewControllers时终止

时间:2014-12-22 05:04:26

标签: ios objective-c iphone uicontainerview

我有ContainerView和三个按钮,如tab。 点按按钮我想将ViewControllers切换到UIContainerView。 当点击按钮App崩溃时,这是我的代码。

- (void) cycleFromViewController: (UIViewController*) oldVC  toViewController: (UIViewController*) newVC{
  [oldVC willMoveToParentViewController:nil];
  [self addChildViewController:newVC];
    [self transitionFromViewController:oldVC toViewController:newVC duration:5 options:0 animations:^{
        newVC.view.frame = oldVC.view.frame;

    } completion:^(BOOL finished) {
        [oldVC removeFromParentViewController];
        [newVC didMoveToParentViewController:self];
        currentVC = newVC;
    }];

}

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Children view controllers <FirstViewController: 0x78e98580> and <ThirdViewController: 0x78e99a60> must have a common parent view controller when calling -[UIViewController transitionFromViewController:toViewController:duration:options:animations:completion:]'

1 个答案:

答案 0 :(得分:0)

错误本身就是指出问题

  

&#39;儿童查看控制器和    必须有一个共同的父视图   调用时的控制器 - [UIViewController   transitionFromViewController:toViewController:持续时间:选择:动画:完成:]&#39;

只需确保您尝试切换的VC属于父级

的容器