How within a tab bar controller do I segue from one view controller to another and retain the tab bar?

StackOverflow https://stackoverflow.com//questions/9694724

  •  13-12-2019
  •  | 
  •  

Question

I have an application with several view controllers controlled from a tab bar controller. From one of these view controllers I want to (on clicking a button) segue to another view controller and retain the tab bar at the bottom of the segued to view.

I've used

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
    if ([segue.identifier isEqualToString:@"newView"]){
        UIViewController *controller =segue.destinationViewController;
        controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
        [self presentModalViewController:controller animated:YES];
    }
 }

This works fine except the tab bar is missing from the segued to view (a placeholder shows for it in the storyboard, but it doesn't show up when the app is run) I've also tried replacing

[self presentModalViewController:controller animated:YES];

with

[self presentViewController:controller animated:YES completion:nil];

but that doesn't work either.

A bit of debugging shows that for the segued-to view controller, the tabBarController property is set to nil.

Is there anyway to retain the tab bar in the segued-to view controller?

Was it helpful?

Solution

From your explanation, I don't think you want a modal controller. Modal is used to overlay, rendering your tab bar useless. From your storyboard, select your segue and select push, not modal.

enter image description here

Push vs Modal (Note the tab bar):

enter image description here enter image description here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top