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

10,293

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

Share:
10,293
John
Author by

John

New to iPad development

Updated on July 31, 2022

Comments

  • John
    John almost 2 years

    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?

  • John
    John about 12 years
    I am using Push not Modal. The tabbar is shown in the storyboard, but does not actually appear when the app is run
  • Gobot
    Gobot about 12 years
    To initiate the segue from code use [self performSegueWithIdentifier:@"theSegueIdentifier" sender:selfOrSomeObject] which is a method of UIViewController. This line controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; [self presentModalViewController:controller animated:YES]; is used for modal transitions not pushes. Remove this line.
  • Gobot
    Gobot about 12 years
    Also from Apple docs for presentModalViewController:animated..."On iPhone and iPod touch devices, the view of modalViewController is always presented full screen. On iPad, the presentation depends on the value in the modalPresentationStyle property.
  • John
    John about 12 years
    I had started with the code as you suggest and couldn't get the segue working until I inserted the extra lines. I've now figured out that push segues only work within a Navigation controller (and can get that working). I thought the Navigation controller was going to be a problem, but I found the "bar visibility checkbox" and I'm dismissing the view with [self.navigationController popViewControllerAnimated:NO];. Thanks for your help, especially the doc quote, which I'd read but forgotten.