我可以以编程方式更改标签项的第一个屏幕吗?
例如,
当用户在标签A中时,点击那里的按钮,用户将是 使用屏幕1导航到Tab C但是,当用户在Tab C中时,在 点击此处的按钮,用户将通过屏幕2导航到Tab C. 因此,屏幕1和2都将是Tab C的第一个屏幕 取决于用户来自何处。
我能实现这样的目标吗? 谢谢!
答案 0 :(得分: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];