好傢伙,如何正確導航到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)時 - 我不再需要它們了。
希望我明確。
感謝您的幫助。我真的很喜歡它。
我已經一派爲溶液,有一種說我需要設置tabBarController作爲根視圖控制器。是對的嗎?我怎樣才能做到這一點 ? – 2010-07-10 06:47:03