如何获取UIStoryBoard segued UITabbarController参考

时间:2014-08-06 09:37:39

标签: ios objective-c uitabbarcontroller uistoryboard uistoryboardsegue

我的故事板从UINavigationController开始,然后是UIViewController,从此UIViewController开始只是UITabbarController。我想要这个UITabbarController引用,但是从另一个视图控制器,我怎么能得到它?

2 个答案:

答案 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];
相关问题
最新问题