64位iOS设备UIViewControllerHierarchyInconsistency

问题描述:

我正在开发一个iPad应用程序,它有一个单一的视图控制器(称为ContentViewController),其中有3个不同的视图。64位iOS设备UIViewControllerHierarchyInconsistency

  1. 滑块视图 - 从底部打开,其中包含图标列表。基于选择一个图标,我有内容的浏览加载视图控制器
  2. 控制视图 - 有几个按钮和文本屏幕的左侧
  3. 容器视图 - 这包括屏幕,在这里我想很大一部分基于图标的从滑块选择负载视图控制器

这是我是如何实现它

在应用启动(首次),我通常在容器视图,其具有加载主视图控制器与应用相关的项目的表格视图。每个视图控制器都在导航控制器中,我在容器视图中加载该导航控制器

当我在滑块视图中选择一个图标时,我正在加载视图控制器。

以下是我实现这样做的东西与名称ContentViewController视图控制器的代码:

- (void) itemSelected: (UIViewController *) viewController 
{ 
    // I am storing view controller in a instance variable currentViewController. The currentViewController is declared as @property (nonatomic , strong) UIViewController *currentViewController under @interface in header file 
    if(_currentViewController == nil) 
    { 
     // This part of code gets executed for the first time, when there is no view controller available in ContainerView 
     _currentViewController = viewController; 
     [self addChildViewController:_currentViewController]; 
     [self.containerView addSubview:_currentViewController.view]; 
    } 
    else if(_currentViewController != viewController) 
    { 
     // If a view controller is already opened in Container View and when I click a icon from the slider, this par of code is getting executed 
     [self addChildViewController:viewController]; 
     [self transitionFromViewController:_currentViewController 
         toViewController:viewController 
           duration:0 
           options:UIViewAnimationOptionTransitionNone 
          animations:^{} 
          completion:^(BOOL finished){ 
           [_currentViewController removeFromParentViewController]; 
           _currentViewController = viewController; 
           [_currentViewController didMoveToParentViewController:self]; 
          } 
    ];   
    } 
} 

上面提到的代码在iPad2和iPad3的,这是32位的装置工作正常。

Terminating app due to uncaught exception 'UIViewControllerHierarchyInconsistency', reason: 'child view controller:<UINavigationController: 0x136d76130> should have parent view controller:(null) but actual parent is:<ContentViewController: 0x136d39680>' 
*** First throw call stack: 
(0x183642950 0x19001c1fc 0x183642890 0x186688f00 0x18661484c 0x186613ff4 0x10009a224 0x1001104c8 0x18673d798 0x1867fe234 0x186692470 0x1865fe4a4 0x1836030a8 0x183600330 0x1836006bc 0x1835416d0 0x1891ddc0c 0x186672fdc 0x100058028 0x19060faa0) 
libc++abi.dylib: terminating with uncaught exception of type NSException 

我试图等除去transitionFromViewController并用下面的代码替换的各种选项:

[_currentViewController willMoveToParentViewController:nil]; 
    [_currentViewController removeFromParentViewController]; 
    _currentViewController = firstView; 
    [_currentViewController didMoveToParentViewController:self]; 

    [self addChildViewController:_currentViewController]; 
    [self.containerView addSubview:_currentViewController.view]; 
但是当我运行在iPad空气(64位装置)本申请中,它是以下错误崩溃在transitionFromViewController投掷

但它在最后一行[self.containerView addSubview ....]中再次崩溃,与iPad Air中提到的错误相同。我不知道如何继续,我不明白为什么这个问题只发生在64位设备上。有人能帮我解决这个问题吗?

在此先感谢!

Vignesh

我能够通过更改代码来解决此问题。在前面的代码中,我将视图控制器添加为子视图控制器,并从父视图中删除了先前的视图控制器。该代码在非64位设备上工作正常,但不在64位设备上。所以我只是将视图控制器的视图添加到容器视图的子视图中,并从超级视图中删除了以前的视图控制器。这里是修改的代码供参考:

if(_currentViewController == nil) 
{ 
    _currentViewController = viewController; 
    [self.containerView addSubview:viewController.view]; 
} 
else if(_currentViewController != viewController) 
{ 
    [_currentViewController.view removeFromSuperview]; 
    [self.containerView addSubview:viewController.view]; 
    _currentViewController = viewController; 
} 

它在所有设备上都能正常工作。