How can I use Embed Segue in iOS 5?

iOS 6 introduced Embed Segue, allowing the use of custom container controllers in Storyboards. Is there a way to duplicate this for iOS 5?

+5
source share
2 answers

I duplicated functionality by subclassing UIStoryboardSegue.

In Interface Builder, I create a custom segue and set its' class to my subclass (QCEmbedSegue). In my parent view controller's viewDidLoad I call performSegueWithIdentifier:sender .

QCEmbedSegue simply overrides perform :

 - (void)perform { [self.sourceViewController addChildViewController:self.destinationViewController]; [[self.sourceViewController view] addSubview:[self.destinationViewController view]]; [self.destinationViewController didMoveToParentViewController:self.sourceViewController]; } 

http://www.quentamia.com/blog/embed-segue-in-ios-5/

-1
source

The problem here is that the view controller of a child view is often added as a subtask of some view of the container of the parent view controller. Since you cannot have sessions from random UIView controls that prevent you from creating segues from the UIView container UIView for the child scene. Thus, you just need to write the code yourself.

Fortunately, these are just the four lines of code that are listed in Adding a child controller from the View controller programming guide. Personally, I could change this code a bit by specifying the following method 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 } 

However, I made custom settings for changing the active child controller from one scene to another, but this is, in fact, just a variation of the code specified later in the above document. But this is not a question of embedding segue, so it is not relevant here

+9
source

All Articles