How can I use an Embed Segue in iOS 5?

前端 未结 2 1133
孤独总比滥情好
孤独总比滥情好 2021-02-09 23:26

iOS 6 introduced the Embed Segue, allowing custom container controllers to be used in Storyboards. Is there anyway to duplicate this for iOS 5?

2条回答
  •  情深已故
    2021-02-09 23:41

    The challenge here is that the child view controller's view is often to be added as a subview of some container view of the parent view controller. Since you can't have segues from random UIView controls, that defies creating segues from a UIView container view to the child's scene. Thus, you just have to write the code yourself.

    Fortunately, it's just those four lines of code referenced in Adding a Child Controller from the View Controller Programming Guide. Personally, I'd might even modify that code slightly, having the following method defined in my view controller:

    - (void) displayChildController:(UIViewController*)childController
                    inContainerView:(UIView *)containerView
    {
       [self addChildViewController:childController];                 // 1
       childController.view.frame = containerView.bounds;             // 2
       [containerView addSubview:childController.view];
       [childController didMoveToParentViewController:self];          // 3
    }
    

    I have, though, done custom segues for changing the active child controller from one scene to the next, but it essentially just a variation of the code listed later in the above referenced document. But that's not an embed segue question, so that's not relevant here

提交回复
热议问题