Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use an Embed Segue in iOS 5?

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

like image 508
Quentamia Avatar asked Feb 05 '13 19:02

Quentamia


1 Answers

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

like image 164
Rob Avatar answered Sep 20 '22 16:09

Rob