问题:运行在4.3模拟器上的程序,到5.01失败了,错误信息如下
MGSplitView[839:f803] *** Terminating app due to uncaught exception 'UIViewControllerHierarchyInconsistency',
reason: 'child view controller:<RootViewController: 0x6886380> should have parent view controller:<MGSplitViewController: 0x6ca1c00> but actual parent is:<UINavigationController: 0x6886980>'
解决方案:
UINavigationController *test=[[UINavigationController alloc] initWithRootViewController:detailViewController];
test.navigationBar.hidden=YES;
[test retain];
//invokes a method of the receiver on the current thread using the default mode after a delay.
[rootViewController performSelector:@selector(selectFirstRow) withObject:nil afterDelay:0];
[detailViewController performSelector:@selector(configureView) withObject:nil afterDelay:0];
self.splitViewController.viewControllers=[[NSArray alloc] initWithObjects:
rootViewController
,test, nil];
代码修改:
UINavigationController *root=[[UINavigationController alloc] initWithRootViewController:rootViewController]
UINavigationController *test=[[UINavigationController alloc] initWithRootViewController:detailViewController];
test.navigationBar.hidden=YES;
[test retain];
//invokes a method of the receiver on the current thread using the default mode after a delay.
[rootViewController performSelector:@selector(selectFirstRow) withObject:nil afterDelay:0];
[detailViewController performSelector:@selector(configureView) withObject:nil afterDelay:0];
self.splitViewController.viewControllers=[[NSArray alloc] initWithObjects:root,test, nil];
看完下图就明白为什么这么修改了:
NavigationController的rootviewController 对应了class:rootviewController //
在nib中的 结构,和用代码修改后的view controller结构不一样了,因此在ios 5的情况下,检查严格了,就出错了:
也有一些提出的解决此类问题的方法:
self.view=xxxxxcontroller.view
替换为:self.view addsubview:xxxcontroller.view