Switching between UIViewControllers using UISegmentedControl

I have a navigation structure → navigationcontroller. In one of these tabs, I want to switch between two UIViewControllers ( KalViewController and, more precisely, UITableViewController) using the UISegmentedControl located in the Navigation Bar.

I currently have a third UIViewController that pops up and pushes the corresponding ViewControllers when the segment value changes. I don’t think this is the right way to do this, and it also destroys the navigation stack (when I click on the bar element, the navigation controller goes to the root controller, which will not work). And one more error related to the Kal component.

So what is the right way to do this?

+1
source share
1 answer

The right way to do this is to get the controller to handle UISegmentedControladding controller views as subviews.

[self.view addSubview:controller.view];

It is your responsibility to send viewWillAppear:, etc.

EDIT: The offset you are talking about can be adjusted with:

controller.view.frame = CGRectMake(x, y, width, height);

EDIT 2: In response to tc. comment:

From the documentation UISplitViewController:

Forwarding messages to child view controllers

. . , , . , , . , , viewWillAppear: viewDidAppear: , . , popover, , .

, , . , .

+3

All Articles