我正在開發一個iPad應用程序,它有一個單一的視圖控制器(稱爲ContentViewController),其中有3個不同的視圖。64位iOS設備UIViewControllerHierarchyInconsistency
- 滑塊視圖 - 從底部打開,其中包含圖標列表。基於選擇一個圖標,我有內容的瀏覽加載視圖控制器
- 控制視圖 - 有幾個按鈕和文本屏幕的左側
- 容器視圖 - 這包括屏幕,在這裏我想很大一部分基於圖標的從滑塊選擇負載視圖控制器
這是我是如何實現它
在應用啓動(首次),我通常在容器視圖,其具有加載主視圖控制器與應用相關的項目的表格視圖。每個視圖控制器都在導航控制器中,我在容器視圖中加載該導航控制器
當我在滑塊視圖中選擇一個圖標時,我正在加載視圖控制器。
以下是我實現這樣做的東西與名稱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