Search code examples
iosiphoneobjective-cuitabbarcontrolleruistoryboardsegue

Instantiate Tab bar Controller without Segue


In all other instances I'm using a segue to transition to a tab bar controller, but I have a need now to load up a tab bar controller without a segue. To do this with a regular view I would use this:

EditProfileView *view = [[self storyboard] instantiateViewControllerWithIdentifier:@"editProfileView"];
[self.navigationController pushViewController:view animated:YES];

The EditProfileView is one of the tabs on my tab controller. How do I change this so that it loads all the tabs?


Solution

  • You should push the UITabBarController instead. e.g.

    UITabBarController *tc = [[self storyboard] instantiateViewControllerWithIdentifier:@"tabbarcontroller"];
    [self.navigationController pushViewController:tc animated:YES];
    

    Make sure the tabbarcontroller's storyboard ID is the same

    Also, if you want to present one particular viewcontroller:

    [tc setSelectedViewController:[tc.viewControllers objectAtIndex:0]];