gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-30 03:17:43 25 4
gpt4 key购买 nike

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com