[英]Present a View Controller modally when selected in Tab Bar Controller
I have this pretty standard Tab Bar Controller setup: 我有这个非常标准的标签栏控制器设置:
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];
However, I'm trying to work out how, when the user selects the middle tab (checkInViewController), I can present that View Controller modally (fullscreen)? 但是,我试图找出如何在用户选择中间选项卡(checkInViewController)时以模态方式(全屏显示)显示View Controller? I'd maybe imagine something in the
viewDidAppear
method in that VC, but I'm not sure if you can present yourself modally, if you're a VC? 我可能会想象该VC的
viewDidAppear
方法中有什么问题,但是我不确定如果您是VC,是否可以模态呈现自己? What's the best approach for this? 最好的方法是什么?
You can use 您可以使用
[self presentViewController:checkInViewController animated:YES completion:nil];
Then hide the tab and navigation bars in the destination view controller's viewWillAppear:
然后在目标视图控制器的
viewWillAppear:
隐藏选项卡和导航栏viewWillAppear:
-(void)viewWillAppear:(BOOL)animated {
[self.navigationController setNavigationBarHidden:YES animated:YES];
[self.tabBarController.tabBar setHidden:YES];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.