Skip to content

Instantly share code, notes, and snippets.

@fjolnir
Created September 8, 2014 12:22
Show Gist options
  • Save fjolnir/2ccd1e114355bfb89cc4 to your computer and use it in GitHub Desktop.
Save fjolnir/2ccd1e114355bfb89cc4 to your computer and use it in GitHub Desktop.
#import "CYContainerViewController.h"
@implementation CYContainerViewController
- (void)setContainedViewController:(UIViewController * const)aController
{
[self willChangeValueForKey:@"containedViewController"];
[self.containedViewController willMoveToParentViewController:nil];
[self.containedViewController removeFromParentViewController];
[self.containedViewController.view removeFromSuperview];
[self.containedViewController didMoveToParentViewController:nil];
aController.view.frame = self.view.bounds;
aController.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[aController willMoveToParentViewController:self];
[self addChildViewController:aController];
[self.view addSubview:aController.view];
[aController didMoveToParentViewController:self];
_containedViewController = aController;
[self didChangeValueForKey:@"containedViewController"];
}
@end
@implementation CYContainmentSegue
- (void)perform
{
NSAssert([self.sourceViewController isKindOfClass:[CYContainerViewController class]],
@"CYContainmentSegue must be used with a CYContainerViewController.");
CYContainerViewController * const container = self.sourceViewController;
container.containedViewController = self.destinationViewController;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment