首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将两个UINavigationControllers添加到选项卡栏时崩溃

将两个UINavigationControllers添加到选项卡栏时崩溃
EN

Stack Overflow用户
提问于 2012-08-09 14:59:55
回答 1查看 252关注 0票数 0

我有一个视图,它有两个子视图,当在选项卡栏中添加这两个子视图时,它会在main中崩溃。以下是代码..

代码语言:javascript
复制
        block_list = [[ofi_vc_blocked_list alloc] init];
        ab_blk_navig_controller = [[UINavigationController alloc] initWithRootViewController:block_list];
        ab_navig_controller = [[UINavigationController alloc] initWithRootViewController:ab_window];
        ab_tab_bar = [[UITabBarController alloc] init]; // ab_tab_bar is tab bar controller
        ab_tab_bar.viewControllers = [NSArray arrayWithObjects:ab_navig_controller, ab_blk_navig_controller, nil];

在执行此操作时,它会崩溃,并显示以下错误:

代码语言:javascript
复制
Terminating app due to uncaught exception 'UIViewControllerHierarchyInconsistency', reason: 'child view controller:<ofi_vc_address_book: 0x6868710> should have parent view controller:<ofi_vc_main_page_controller: 0x6c4b830> but actual parent is:<UITabBarController: 0x6869830>'

伙计们,你们知道吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-08-09 15:21:51

我已经给出了一个例子,为第一个tabBar2添加以下语句,为第二个添加以下语句。

代码语言:javascript
复制
UITabBarItem *tabBar1 = [[UITabBarItem alloc] initWithTitle:@"" image:[UIImage      imageNamed:@""] tag:0];
navigation1.tabBarItem = tabBar1;

 UITabBarItem *tabBar2 = [[UITabBarItem alloc] initWithTitle:@"" image:[UIImage      imageNamed:@""] tag:1];
navigation2.tabBarItem = tabBar2;

tabBarCon.viewControllers = [NSArray arrayWithObjects:navigation1,navigation2, nil];
self.window.rootViewController = tabBarCon;
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11878275

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档