1

好傢伙,如何正確導航到navigationController到tabBarController與它自己的navigationControllers

我有一個一般設計問題的iPhone應用程序。 我想知道如何從普通視圖與navigationController到tabBarController與標籤其中每個標籤都有自己的navigationController(不需要第一個navigationController更多)的主要原則。

讓我告訴你我是如何做到這一點:

首先,我加入了一些看法與一鍵navigationController。 AppDelegate中添加此navigationController(與視圖控制器的課程)作爲子視圖窗口:

[window addSubview:navigationController.view]; 

當我到了新的視圖(navigationController頂部)我按一下按鈕,帶我到新的觀點具有tabBarController(與他自己的navControllers):

SearchViewController *searchViewController = [[SearchViewController alloc] initWithNibName:@"SearchView_iPhone" bundle:nil]; 
searchViewController.tabBarItem.title = @"FirstTab"; 
UINavigationController *searchNavigationController = [[UINavigationController alloc] initWithRootViewController:searchViewController]; 

SettingsViewController *settingsViewController = [[SettingsViewController alloc] initWithNibName:@"SettingsView_iPhone" bundle:nil]; 
settingsViewController.tabBarItem.title = @"SecondTab"; 
UINavigationController *settingsNavigationController = [[UINavigationController alloc] initWithRootViewController:settingsViewController]; 

//Add navigation controllers to tabBar controller 
tabBarController = [[UITabBarController alloc] init]; 
tabBarController.viewControllers = [NSArray arrayWithObjects:searchNavigationController, dictionariesNavigationController, settingsNavigationController, nil]; 

好吧,我添加到tabBarController的所有視圖(與navControllers)。我所要做的就是按下tabBarController待觀察:

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

但在那之後我看到navigationController從第一種觀點仍然存在與tabBars意見。這是合乎邏輯的,因爲我使用navigationController推送了tabBarController。所以我這樣做是爲了隱藏它:

self.navigationController.navigationBarHidden = YES; 

現在看起來沒問題。所有tabBar視圖都有它自己的navController。

主要問題:當我想從settingsViewController中的子查看錶(settingsTableViewCell)推入另一個視圖(settingsResultsViewController)時,什麼都不會發生。下面是代碼:

SettingsResultsViewController *settingsResultsViewController = [[SettingsResultsViewController alloc] initWithNibName:@"SettingsResultsView_iPhone" bundle:nil]; 
[self.navigationController pushViewController:settingsResultsViewController animated:YES]; 

我也試圖用的appDelegate推動這個觀點是這樣的:

[delegatePhone.settingsViewController.navigationController pushViewController:settingsResultsViewController animated:YES]; 
[delegatePhone.firstViewController.navigationController pushViewController:settingsResultsViewController animated:YES]; 

但同樣沒有任何反應。

我假設主要問題在navigationControllers中。第一個navigationController仍然在後面的某個位置,而我想用該特定tabBar上的當前navController進行推送。

有沒有辦法從第一個視圖,而不是導航控制器推新視圖(tabBarController在我的情況)?

我想要的一切是當firstView上的按鈕將應用程序帶到tabBarController並忘記firstView(和第一個navigationController)時 - 我不再需要它們了。

希望我明確。

感謝您的幫助。我真的很喜歡它。

+0

我已經一派爲溶液,有一種說我需要設置tabBarController作爲根視圖控制器。是對的嗎?我怎樣才能做到這一點 ? – 2010-07-10 06:47:03

回答

0

您可以通過調用presentModalViewController:animated:而不是將其推送到導航堆棧來顯示標籤欄控制器。如果你根本不需要第一個導航控制器,你應該用標準的視圖控制器替換它。

+0

感謝您的建議,但我仍然無法在tabBar視圖中的tableViewCell中推送另一個視圖。當我測試這個代碼時,我得到零: if(self.navigationController == nil) \t NSLog(@「navigation is nil」);如果(self.parentViewController.navigationController == nil) \t NSLog(@「parent navigation is nil」); 自我和父導航控制器都是零怎麼會? – 2010-07-11 06:11:33

0

Tweetie作者在關於標籤欄和中殿控制器的話題中評論了一段時間。這個線程有幫助嗎?

Tab bar controller inside a navigation controller, or sharing a navigation root view

+0

這對我沒有幫助。我試圖推動tabBarController作爲modalView(presentModalViewController)。但仍然沒有運氣。我仍然無法從firstViewBar的子視圖tableView推新視圖。 任何人都可以幫我解決這個問題嗎? – 2010-07-11 18:59:36

相關問題