我的故事板从UINavigationController
开始,然后是UIViewController
,从此UIViewController
开始只是UITabbarController
。我想要这个UITabbarController
引用,但是从另一个视图控制器,我怎么能得到它?
答案 0 :(得分:1)
如果您的segue从UIViewController
变为UITabbarController
,则segue.destinationViewController
实际上是您的UITabbarController
,因此您可以像UIViewController
类中那样访问它(记得在故事板中添加segue标识符)
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"YOURSEGUEIDENTIFIER"]) { //<-- YOURSEGUEIDENTIFIER needs to match identifier you set up in storyboard
UITabbarController *tvc = (UITabbarController*)segue.destinationViewController;
}
}
//我刚刚从评论区域移动了代码
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; // <-- make sure Main match name of your storyboard
UITabbarController *tvc = [storyboard instantiateViewControllerWithIdentifier:@"YourIdentifierFromStoryboard"];
[tvc setModalPresentationStyle:UIModalPresentationFullScreen];
请记住在故事板中为表栏控制器设置标识符。
答案 1 :(得分:1)
您可以使用Storyboard ID进行此操作。将Storyboard ID设置为TabBarController。
以下是您可以在任意位置调用的代码。
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"nameOfStoryboard" bundle:nil];
TabBarController * destViewController = [storyboard instantiateViewControllerWithIdentifier:@"TheIDOfTabBarController"];
[self.navigationController pushViewController:destViewController animated:YES];