如何在 viewController 推送操作后管理新视图上的 TabBarController
我在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您想用下面的代码做什么?
您说您的应用程序有 3 个选项卡,每个选项卡都有一个导航控制器。因此,您应该做的是将导航控制器添加到 tabBarController.viewControllers 中(您已经这样做了),但是您需要将 tabBarController 设置为根视图控制器。
What are you trying to do with the following code?
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 thetabBarController
as the root view controller.我已经这样做了并且有效:
感谢你们的帮助。
I have done it this way and it works:
Thanks for your help guys.