Reputation: 3071
I have storyboard starting with UINavigationController
then UIViewController
and from this UIViewController
just a segue to UITabbarController
. I want this UITabbarController
reference but from another view controller, How I can get this?
Upvotes: 0
Views: 509
Reputation: 893
You can make this with Storyboard ID. Set a Storyboard ID to TabBarController.
And here is the code that you can call it where you want.
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"nameOfStoryboard" bundle:nil];
TabBarController * destViewController = [storyboard instantiateViewControllerWithIdentifier:@"TheIDOfTabBarController"];
[self.navigationController pushViewController:destViewController animated:YES];
Upvotes: 1
Reputation: 25459
If your segue goes from UIViewController
to UITabbarController
the segue.destinationViewController
is actually your UITabbarController
, so you can access it like that in the UIViewController
class (remember to add segue identifier in the storyboard)
-(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;
}
}
// I just moved code from comment area
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; // <-- make sure Main match name of your storyboard
UITabbarController *tvc = [storyboard instantiateViewControllerWithIdentifier:@"YourIdentifierFromStoryboard"];
[tvc setModalPresentationStyle:UIModalPresentationFullScreen];
just remember to set up identifier for your table bar controller in storyboard.
Upvotes: 1