Switch between UIViewControllers using UISegmentedControl

后端 未结 1 1894
情深已故
情深已故 2020-12-20 05:23

I have a tabbar -> navigationcontroller structure. In one of these tabs, I want to switch between two UIViewControllers (a KalViewController and a UITableViewController to b

相关标签:
1条回答
  • 2020-12-20 06:19

    The right way to do it is to have the controller handling the UISegmentedControl add the views of the controllers as subviews.

    [self.view addSubview:controller.view];
    

    It's your responsibility to send viewWillAppear: and so on.

    EDIT: The offset you're talking about can be adjusted using:

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

    EDIT 2: In response to tc.'s comment:

    From the documentation of UISplitViewController:

    Message Forwarding to Its Child View Controllers

    A split view controller interposes itself between the application’s window and its child view controllers. As a result, all messages to the visible view controllers must flow through the split view controller. This works generally as you might expect and the flow of messages should be relatively intuitive. For example, view appearance and disappearance messages are sent only when the corresponding child view controller actually appears on screen. Thus, when a split view controller is first displayed in a portrait orientation, it calls the viewWillAppear: and viewDidAppear: methods of only the view controller that is shown initially. The view controller that is presented using a popover does not receive those messages until the popover is shown or until the split view controller rotates to a landscape orientation.

    This is not magical and there is no reason why you wouldn't be able to write a similar controller yourself. In fact I've done it and it worked just fine.

    0 讨论(0)
提交回复
热议问题