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

时间:2012-08-09 06:59:55

标签: iphone objective-c ios xcode

我有一个视图,它有两个子视图,同时在标签栏中添加这两个子视图,它在main中崩溃。以下是代码..

        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];

在执行此操作时,它会因以下错误而崩溃:

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>'

任何想法的人?

1 个答案:

答案 0 :(得分:0)

我举了一个例子,为第一个和第二个tabBar2添加以下语句。

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;