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

时间:2010-07-06 19:01:51

标签: iphone xcode uitabbarcontroller uitabbar

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

查看“第一”控制器后出现问题。应用程序崩溃......

请求帮助。

此致 博鲁特

2 个答案:

答案 0 :(得分:1)

你想用以下代码做什么?

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

你说你的应用有3个标签,每个标签都有一个导航控制器。因此,您应该将导航控制器添加到tabBarController.viewControllers(您做过),但是您需要将tabBarController设置为根视图控制器。

答案 1 :(得分:1)

我这样做了它并且有效:

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

感谢您的帮助。

相关问题