2012-08-09 47 views
0

我有一個視圖,它有兩個子視圖,在標籤欄中添加這兩個子視圖時,它會在主體中崩潰。以下是代碼..將兩個UINavigationControllers添加到標籤欄時崩潰

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

任何想法的傢伙?

+0

ab_window從哪裏來?它在哪裏製造?這聽起來像ab_window已經在視圖層次結構中,你試圖強制它進入一個不同的地方,導致異常。 – Kalle 2012-08-09 20:05:15

回答

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;