2010-07-06 40 views
1

使用tabBarController構建應用程序時出現問題。 如果我從AppDelegate構建它,使用navigationController做tabBarController沒有問題。如何在viewController推送操作後在新視圖上管理TabBarController

但現在我所經歷過的問題時,我想創建一個新的tabBarController視圖(3個標籤,每個人都有導航控制器)從以前的導航控制器推後。 它根本不起作用。

下面是代碼:

MainViewController *mainViewController = [[MainViewController alloc] initWithNibName:@"MainView_iPhone" bundle:nil]; 
mainViewController.tabBarItem.title = @"First"; 
UINavigationController *mainNavigationController = [[UINavigationController alloc] initWithRootViewController:mainViewController]; 

DictionariesViewController *dictionariesViewController = [[DictionariesViewController alloc] initWithNibName:@"DictionariesView_iPhone" bundle:nil]; 
dictionariesViewController.tabBarItem.title = @"Second"; 
UINavigationController *dictionariesNavigationController = [[UINavigationController alloc] initWithRootViewController:dictionariesViewController]; 

tabBarController = [[UITabBarController alloc] init]; 
tabBarController.viewControllers = [NSArray arrayWithObjects:mainNavigationController, dictionariesNavigationController, nil]; 

[self.navigationController pushViewController:tabBarController animated:YES]; 

有後視圖是僕射「第一」控制器的問題。應用程序崩潰...

請求幫助。

問候 博魯特

+0

請重新格式化您的代碼。這是很難閱讀的代碼是:) – ryanprayogo 2010-07-06 19:30:48

回答

1

什麼是你想用下面的代碼呢?

[self.navigationController pushViewController:tabBarController animated:YES]; 

你說你的應用有3個選項卡,每個選項卡都有一個導航控制器。因此,您應該做的是將導航控制器添加到tabBarController.viewControllers(您所做的),但是您需要將tabBarController設置爲根視圖控制器。

+0

是的,我的應用程序有3個選項卡,他們每個人都有自己的navigatonController。我爲每個tabBarController添加一個navigationController和view controller。 最後,我推動了新視圖上的所有內容:[self.navigationController pushViewController:tabBarController animated:YES];你是什​​麼意思,我需要將tabBarController設置爲根視圖控制器?你能給我一段代碼表明如何做到這一點?謝謝 – 2010-07-08 12:48:26

+0

在您的應用程序委託中,在將所有導航控制器添加到tabBarController後執行以下操作。 '[窗口setRootViewController:tabBarController];' – ryanprayogo 2010-07-08 14:05:45

+0

的問題是,我不在APPDELETE但第一子視圖創建tabBarController。所以我無法訪問窗口屬性。 如果我總結一下。在AppDelegate中,我首先推入navigationController和一些視圖。在按下按鈕後,我創建了tabBarController,並將其推送到此處,而我不再在AppDelegate中。 謝謝 – 2010-07-11 06:15:41

1

我已經做到了這種方式,它的工作原理:

registerViewController = [[RegisterViewController alloc] initWithNibName:@"RegisterView_iPhone" bundle:nil]; 
AppDelegate_Phone *delegatePhone = [[UIApplication sharedApplication] delegate]; 
[delegatePhone.firstViewController.navigationController pushViewController:registerViewController animated:YES]; 

感謝您的幫助球員。

相關問題