How to switch between UIViewControllers without using a tab bar?

I have a UINavigationController. At the second level of my hierarchy, I want to show a view controller with a toolbar into which I inserted a segmented control. Through it, the user can choose between two "views" of the same page, which we can call A and B (for example, in the Calendar application).

When the user presses segment A, view A should be displayed. When the user presses segment B, view B should be displayed

A and B are complex views, so I prefer to manage them in two separate view controllers called AViewController and BViewController.

I originally thought of inserting AViewController and BViewController into a UITabBarViewController, but in the official pushViewController documentation: animated: I read that the push request controller "cannot be an instance of a tab bar controller."

Do you know how I can switch between AViewController and BViewController without using UITabBarViewController?

Many thanks!

+3
source share
2 answers

You probably want to see a UISegmentView that will give you some buttons that you can use to change the contents of a view.

"" .

, , , .

, UISegment 2 , AViewController BViewController. , . viewDidLoad, , ...

-(void)showAppropriateView {

     if([segment selectedIndex] == A_VIEW_SEGMENT) {
         [self.containerView addSubView:aViewController.view];
         [bViewController.view removeFromSuperView];
     } else {
         [self.containerView addSubView:bViewController.view];
         [aViewController.view removeFromSuperView];
     }
}

, UISegmentView.

+2

( rootView) showSubviewToFront, :

// display view A
[rootView bringSubviewToFront:AViewController.view];

// display view B
[rootView bringSubviewToFront:BViewController.view];
+2

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


All Articles