如何在 viewController 推送操作后管理新视图上的 TabBarController

发布于 2024-09-08 02:32:27 字数 1243 浏览 5 评论 0原文

我在使用 tabBarController 构建应用程序时遇到问题。 如果我从 AppDelegate 构建 tabBarController 和 navigationController ,那么使用 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];

将视图推送到“第一个”控制器后出现问题。应用程序崩溃...

请寻求帮助。

问候 博鲁特

I have a problem building applicatin with tabBarController.
There is no problem doing tabBarController with navigationController if I build it from AppDelegate.

But now I have experienced problem when I want to create new view with tabBarController (3 tabs and each has navigation controllers) after a push from previous navigation controller.
It simply doesnt work.

Here is the code:

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];

There is a problem after view is pushe to "First" controller. Application crashes...

Please for help.

Regards
Borut

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

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

发布评论

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

评论(2

若水般的淡然安静女子 2024-09-15 02:32:27

您想用下面的代码做什么?

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

您说您的应用程序有 3 个选项卡,每个选项卡都有一个导航控制器。因此,您应该做的是将导航控制器添加到 tabBarController.viewControllers 中(您已经这样做了),但是您需要将 tabBarController 设置为根视图控制器。

What are you trying to do with the following code?

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

You said that your app has 3 tabs and each of those tabs have a navigation controller. Therefore, what you should do is to add the navigation controllers to tabBarController.viewControllers (which you did), but then you need to set the tabBarController as the root view controller.

冷︶言冷语的世界 2024-09-15 02:32:27

我已经这样做了并且有效:

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

感谢你们的帮助。

I have done it this way and it works:

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

Thanks for your help guys.

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