0

我可以以编程方式更改选项卡项的第一个屏幕吗?

例如,

当用户在选项卡 A 中时,在点击那里的按钮时,用户将被导航到具有屏幕 1 的选项卡 C 但是,当用户在选项卡 C 中时,在此处点击按钮时,用户将被导航到具有屏幕 2 的选项卡 C。因此,屏幕 1 和 2 都将是 Tab C 的第一个屏幕,具体取决于用户来自哪里。

我可以实现这样的目标吗?谢谢!

4

1 回答 1

0

基于这篇文章How to replace a navigation root controller by tab bar controller in existing iphone app,可以通过以下代码更改视图控制器:

NSMutableArray * viewControllers = [[NSMutableArray alloc]init];


FirstViewController * firstViewController = [[FirstViewController alloc]initWithNibName:@"FirstViewController" bundle:nil];
UINavigationController * nvc = [[UINavigationController alloc] initWithRootViewController:firstViewController];
[firstViewController release];
[viewControllers addObject:nvc];
[nvc release];

SecondViewController * secondViewController = [[SecondViewController alloc]initWithNibName:@"SecondViewController" bundle:nil];
 nvc = [[UINavigationController alloc] initWithRootViewController:secondViewController];
[secondViewController release];
[viewControllers addObject:nvc];
[nvc release];

UITabBarController * tabBarController = [[UITabBarController alloc] init];
tabBarController.viewControllers = viewControllers;
[window addSubview:tabBarController.view];
于 2012-11-16T07:03:46.707 回答