How within a tab bar controller do I segue from one view controller to another and retain the tab bar?
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.
Push vs Modal (Note the tab bar):
Comments
-
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 about 12 yearsI am using Push not Modal. The tabbar is shown in the storyboard, but does not actually appear when the app is run
-
Gobot about 12 yearsTo initiate the segue from code use
[self performSegueWithIdentifier:@"theSegueIdentifier" sender:selfOrSomeObject]
which is a method ofUIViewController
. This linecontroller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; [self presentModalViewController:controller animated:YES];
is used for modal transitions not pushes. Remove this line. -
Gobot about 12 yearsAlso 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 about 12 yearsI 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.