S.J
S.J

Reputation: 3071

How to get UIStoryBoard segued UITabbarController reference

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

Answers (2)

hoya21
hoya21

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

Greg
Greg

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

Related Questions