大家好,
我有一个iPhone应用程序的一般设计问题。
我想知道的主要原则是如何从普通视图与导航控制器到tabBarController与标签,其中每个标签都有自己的导航控制器(不需要第一个导航控制器了)。
我来告诉你我是怎么做的:
首先,我向navigationController添加了一些带有按钮的视图。AppDelegate将此navigationController(当然还有view controller)作为子视图添加到窗口:
[window addSubview:navigationController.view];
当我到达那个新视图(导航控制器在顶部)时,我单击按钮,它会将我带到一个新视图,这个视图有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];
好的,我将所有视图(带有navControllers)添加到tabBarController。我要做的就是推tabBarController让别人看到:
[self.navigationController pushViewController:tabBarController animated:YES];
self.navigationController.navigationBarHidden = YES;
主要问题:当我想从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];
我假设主要问题出在导航控制器上。第一个navigationController仍然在后面的某个地方,而我想用当前navigationController在特定的tabBar上按下。
除了使用navigationController之外,有没有其他方法可以从第一个视图推送新视图(在我的例子中是tabBarController)?
我想要的是当firstView上的按钮是clicke时,应用程序会把我带到tabBarController,完全忘记firstView(和firstnavigationcontroller)——我不再需要它们了。
希望我说清楚。