在选项卡栏控制器中选择时,以模态方式显示视图控制器

时间:2014-10-27 18:33:13

标签: ios objective-c

我有这个非常标准的Tab Bar Controller设置:

UIViewController *homeViewController = [[PLOTHomeViewController alloc] init];
UIViewController *upcomingViewController = [[PLOTUpcomingViewController alloc] init];
UIViewController *checkInViewController = [[PLOTCheckInViewController alloc] init];
UIViewController *watchlistViewController = [[PLOTWatchlistViewController alloc] init];
UIViewController *profileViewController = [[PLOTProfileViewController alloc] init];

PLOTNavigationController *homeNavVC = [[PLOTNavigationController alloc] initWithRootViewController:homeViewController];
PLOTNavigationController *upcomingNavVC = [[PLOTNavigationController alloc] initWithRootViewController:upcomingViewController];
PLOTNavigationController *checkInNavVC = [[PLOTNavigationController alloc] initWithRootViewController:checkInViewController];
PLOTNavigationController *watchlistNavVC = [[PLOTNavigationController alloc] initWithRootViewController:watchlistViewController];
PLOTNavigationController *profileNavVC = [[PLOTNavigationController alloc] initWithRootViewController:profileViewController];

self.tabBarController = [[PLOTTabBarController alloc] init];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:homeNavVC, upcomingNavVC, checkInNavVC, watchlistNavVC, profileNavVC, nil];

但是,我试图弄清楚当用户选择中间选项卡(checkInViewController)时,我能以模态方式呈现视图控制器(全屏)吗?我可以想象一下VC中viewDidAppear方法的某些内容,但我不确定你是否能以模态方式呈现自己,如果你是VC?对此最好的方法是什么?

1 个答案:

答案 0 :(得分:0)

您可以使用

[self presentViewController:checkInViewController animated:YES completion:nil];

然后隐藏目标视图控制器的viewWillAppear:

中的选项卡和导航栏
-(void)viewWillAppear:(BOOL)animated {
    [self.navigationController setNavigationBarHidden:YES animated:YES];
    [self.tabBarController.tabBar setHidden:YES];
}