0

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

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

有什么想法吗?

4

1 回答 1

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;
于 2012-08-09T07:21:50.553 回答