objective-c - IOS5中的UITabbarcontroller抛出UIViewControllerHierarchyInconsistency异常

标签 objective-c uitabbarcontroller ios5

我有以下 UITabbar Controller 的代码:

NSMutableArray *arr = [[NSMutableArray alloc] init];
tabBarController = [[UITabBarController alloc] init];

FirstViewController *firstview = [[FirstViewController alloc] init];
[tabBarControllerViews addObject:firstview];
[firstview release];

 SecondViewController *secondview = [[SecondViewController alloc] init];
[tabBarControllerViews addObject:secondview];
[secondview release];

[tabBarController setViewControllers:arr animated:YES];
[arr release];

self.view = tabBarController.view;

此代码在 IOS4 上运行良好。我在 IOS5 beta 上试过,点击 UITabbarItem 时出现以下错误:

*** Terminating app due to uncaught exception 'UIViewControllerHierarchyInconsistency',
reason: 'child view controller:<FirstViewController: 0x6e03be0> should have parent view
controller:<MainViewController: 0x6816d20> but actual parent is:<UITabBarController: 0x6b0c110>'

最佳答案

替换:

self.view = tabBarController.view;

与:

[self.view addSubview:tabBarController.view];

这也将向后兼容 IOS3 和 4。

关于objective-c - IOS5中的UITabbarcontroller抛出UIViewControllerHierarchyInconsistency异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6279733/

相关文章:

iphone - iOS 5 : How to implement a custom (image) back button

objective-c - 如何通过父 MOC 将更改从一个子托管对象上下文合并到另一个子托管对象上下文?

objective-c - 从您的应用程序内部调用 map 获取方向 - iOS 5 iOS 6

iphone - 我想通过我们的应用程序在 "EverNote"中存储一些数据

ios - 如何在不影响 UICollectionViewCell 的不透明度的情况下设置 UICollectionView 背景的不透明度?

iphone - hidesBottomBarWhenPushed = NO 不起作用?

ios - 当应用程序在选项卡栏 Controller 中加载时,特定选项卡栏项目会隐藏吗?

ios - 从 UIGraphicsImageContext 裁剪区域 CGRect

objective-c - SIMBL 在取景器中调配

iphone - 如何更改 UItabbar 图标图像?