Keep tab bar in view mode after session?

I have a tab bar controller, then a navigation controller, and then the first view controller. As expected, this view controller has a tab bar. However, when I switch from this view, I lose the tab bar. I want him to maintain his position on another VC arising from this first glance. Here is my IB:

enter image description here

I want the tab bar to also appear on the left VC after loading it through segue from the right VC,

How this is achieved, as it is currently disappearing, no matter how I set the tab at the bottom of the VC, as shown above.

+6
source share
2 answers

If you make a modal segue from a view that represents the appearance of the tab bar, it will get rid of the tab bar for the modal view you presented.

Secondly, when you go, you create a new instance of the view controller. Therefore, I assume that you go from view1 to view2 and lose the tab bar, and then go to view1. At this point, you created view1, view2 and a second copy of view1, which does not have a tab bar.

I would suggest one of two things.

1.) If you want to save the tabs below when you switch from view1 to view2, then click on view1, select "Editor / Paste / Navigation" at the top of the screen. This will add your view1 to the navigation controller. Then, if you change your transition from Modal to Push, it will keep your tab bars at the bottom. The navigation bar at the top also makes it easy to return to view 2, to display 1 correctly (choosing a view) rather than creating a new segment. If you don’t like the navigation bar, you can change the “Top bar” property to “No” in the inspector. Then you will need to create another way in view2 to return to view1. (BY PURCHASING THE CONTROLLER, NOT FOLLOWING)

2) If you do not want to configure the navigation controller, it will be a little more difficult for you to save the contents of the tab bar at the bottom of the view2 controller. Actually, I'm not sure if you can do this with modal segue at all, you probably have to write some kind of custom segue. In any case, if you want to go to view1 and go to the correct controller (and not to the new version without tabs), then you need to attach an action to any button that you use to execute and use the following code (I also added code for the navigation controller clicks segments if you create a navigation controller and get rid of the navigation bar.)

For Modal Segue:

[self dismissModalViewControllerAnimated:YES]; 

In Push segue mode:

 [self.navigationController popViewControllerAnimated:YES]; 

It’s best to use the navigation controller method, as you are sure to keep your tabs. You can either use the navigation bar to return (an easy way, no code), or you can get rid of it and use the button and code above.

Good luck Click on the green flag if this helps

+6
source

From the storyboard, you set the transition from the launch view controller to the root panel controller of the tab bar. Then you use segue to transfer data to a specific item view controller

  override func prepare(for segue: UIStoryboardSegue, sender: Any?) { let vc = segue.destination as! TabBarRootViewController let vc1 = vc.viewControllers?[0] as! specificItemViewController vc1.destinationVariable = self.startingControllerVariable 
0
source

Source: https://habr.com/ru/post/1265974/


All Articles