我有以下 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/