Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 570
John Avatar asked Mar 14 '12 01:03

John


People also ask

How do I segue to another view controller?

So, Ctrl+Drag from the “Go to Other View Controller” button, to somewhere in the second View Controller. It can be anywhere in the main box of the second view controller. When you release, it will show you a box like the one below. This lets you set what kind of segue you want to use.

How do you add a segue between two view controllers in a storyboard?

To create a segue between view controllers in the same storyboard file, Control-click an appropriate element in the first view controller and drag to the target view controller. The starting point of a segue must be a view or object with a defined action, such as a control, bar button item, or gesture recognizer.

How do I connect my controller to my tab bar controller?

To add the new View Controller to the Tab Bar Controller, right-click the Tab Bar Controller and drag it to the new View Controller. Select Relationship Segue. Now, the Tab Bar Controller has the third item and Relationship “view controllers” to “View Controller”.

How do I add more tabs to my tab bar controller?

To add a tab, first drag a new View Controller object to the storybard. Next control-drag from the tab bar controller to new view controller and select view controllers under Relationship Segue . Your tab bar controller will update with a new tab.


1 Answers

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 hereenter image description here

like image 109
Gobot Avatar answered Oct 02 '22 20:10

Gobot