【发布时间】:2013-11-27 17:21:09
【问题描述】:
我有几个视图控制器连接到我的 tabbarcontroller。每个都相应地命名,FirstVC,SecondVC 等。当我打开让我们说 ThirdVC 并按下一个按钮时,我希望它调出另一个 VC,我们称之为 ThirdChildVC,然后在 ThirdChildVC 上有一个返回到 ThirdVC 的按钮。我能做到这一点的唯一方法是包含以下代码:
[[[UIApplication sharedApplication] delegate] performSelector:@selector(setupRootViewController1)];
并调用另一个方法,我们称之为 setupRVC1,它与 setupRVC(见下文)相同,除了选项卡中显示的 VC 的顺序。但是,我希望能够保持 tabbaritems 的顺序,以便它始终按顺序显示 FirstVC、SecondVC 等,但是当按下 ThirdChildVC 上的按钮时,能够将 ThirdVC 显示为默认 VC。
- (void)setupRVC
{
UIViewController *firstVC = [[FirstVC alloc]initWithNibName:@"FirstVC" bundle:nil];
UIViewController *secondVC = [[SecondVC alloc]initWithNibName:@"SecondVC" bundle:nil];
UIViewController *thirdVC = [[ThirdVC alloc]initWithNibName:@"ThirdVC" bundle:nil];
UIViewController *fourthVC = [[FourthVC alloc]initWithNibName:@"FourthVC" bundle:nil];
UIViewController *fifthVC = [[FifthVC alloc]initWithNibName:@"FifthVC" bundle:nil];
self.tabBarController = [[UITabBarController alloc]init];
self.tabBarController.viewControllers = @[firstVC, secondVC, thirdVC, fourthVC, fifthVC];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
- (void)setupRVC1
{
UIViewController *firstVC = [[FirstVC alloc]initWithNibName:@"FirstVC" bundle:nil];
UIViewController *secondVC = [[SecondVC alloc]initWithNibName:@"SecondVC" bundle:nil];
UIViewController *thirdVC = [[ThirdVC alloc]initWithNibName:@"ThirdVC" bundle:nil];
UIViewController *fourthVC = [[FourthVC alloc]initWithNibName:@"FourthVC" bundle:nil];
UIViewController *fifthVC = [[FifthVC alloc]initWithNibName:@"FifthVC" bundle:nil];
self.tabBarController = [[UITabBarController alloc]init];
self.tabBarController.viewControllers = @[ThirdVC, FirstVC, SecondVC, ThirdVC, FourthVC, FifthVC];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
【问题讨论】:
标签: ios objective-c uiviewcontroller uitabbarcontroller