如何使用它自己的navigationControllers正确地从navigationController导航到tabBarController

发布于 2024-09-08 21:25:01 字数 2956 浏览 2 评论 0原文

大家好,

我遇到了 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];

好的,我将所有视图(带有 navControllers)添加到 tabBarController 中。我所要做的就是推动 tabBarController 使其可见:

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

但之后我看到第一个视图中的 navigationController 仍然存在于带有 tabBar 的视图上。这是合乎逻辑的,因为我用 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];

但同样没有任何反应。

我认为主要问题出在导航控制器中。当我想在特定的 tabBar 上推送当前的 navController 时,第一个 navigationController 仍然在后面的某个地方。

除了使用 navigationController 之外,还有其他方法可以从第一个视图推送新视图(在我的情况下是 tabBarController )吗?

我想要的只是当单击firstView 上的按钮时,应用程序会将我带到tabBarController 并完全忘记firstView(和第一个navigationController) - 我不再需要它们了。

希望我说清楚了。

感谢您的帮助。我真的很欣赏它。

Hello guys,

I have a general design problem with iPhone application.
I want to know the main principle how to go from normal view with navigationController to tabBarController with tabs where each tab has it's own navigationController (dont need first navigationController any more).

Let me show you how I made this:

First I added some view with a button to navigationController. AppDelegate adds this navigationController (with view controller of course) as subView to window:

[window addSubview:navigationController.view];

When I get to that new view (with navigationController on top) I click on button that takes me to new view which has tabBarController (with his own 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];

Ok, I added all views (with navControllers) to tabBarController. All I have to do is to push tabBarController to be seen:

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

But after that I see that navigationController from first view is still present on views with tabBars. This is logical, because I pushed tabBarController with navigationController. So I did this to hide it:

self.navigationController.navigationBarHidden = YES;

Now it looks ok. All of the tabBar views has it's own navController.

THE MAIN PROBLEM: When I want to push another view (settingsResultsViewController) from subviewed table (settingsTableViewCell) which is in settingsViewController nothing happens. Here is the code:

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

I also tried to push this view with appDelegate like this:

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

But again nothing happens.

I assume that the main problem is in navigationControllers. The first navigationController is still somewhere in the back while I want to push with current navController on that particular tabBar.

Is there a way to push new view (tabBarController in my case) from first view other than with navigationController ?

All I want is when the button on firstView is clicke that app takes me to tabBarController and forget about firstView (and first navigationController) at all - I dont need them any more.

Hope I made it clear.

Thanks for all your help. I really appriciate it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

别靠近我心 2024-09-15 21:25:01

您可以通过调用 PresentModalViewController:animated: 来显示选项卡栏控制器,而不是将其推送到导航堆栈。如果您根本不需要第一个导航控制器,您可能应该将其替换为标准视图控制器。

You could display the tab bar controller by calling presentModalViewController:animated: instead of pushing it to a navigation stack. And if you don't need the first navigation controller at all, you should probably replace it with a standard view controller.

我不是你的备胎 2024-09-15 21:25:01

Tweetie 作者不久前在一个有关选项卡栏和 nave 控制器的帖子中发表了评论。该线程有帮助吗?

标签栏导航控制器内的控制器,或共享导航根视图

The Tweetie author commented in a thread concerning tab bars and nave controllers a while back. Does this thread help?

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文