Skip to content

Instantly share code, notes, and snippets.

@stephsharp
Created June 14, 2013 01:35
Show Gist options
  • Save stephsharp/5778803 to your computer and use it in GitHub Desktop.
Save stephsharp/5778803 to your computer and use it in GitHub Desktop.
Embed Segue for iOS5
//
// iOS5EmbedSegue.h
// Created by Stephanie Sharp on 2/05/13.
//
#import <UIKit/UIKit.h>
@interface iOS5EmbedSegue : UIStoryboardSegue
@property (nonatomic, strong) UIView * containerView;
@end
//
// iOS5EmbedSegue.m
// Created by Stephanie Sharp on 2/05/13.
//
// Helpful links:
// http://stackoverflow.com/questions/14432310/embed-segue-ios-5
// http://www.quentamia.com/blog/embed-segue-in-ios-5/
#import "iOS5EmbedSegue.h"
@implementation iOS5EmbedSegue
@synthesize containerView;
- (void)perform
{
if (!self.containerView)
self.containerView = [self.sourceViewController view];
[self.sourceViewController addChildViewController:self.destinationViewController];
[self.containerView addSubview:[self.destinationViewController view]];
[self.destinationViewController didMoveToParentViewController:self.sourceViewController];
}
@end
@stephsharp
Copy link
Author

  1. If you do not set the containerView property, it will default to the sourceViewController's view. Otherwise, the segue will embed the destinationViewController in the containerView.
  2. As far as I am aware, there is no way to specify the containerView in the storyboard.

I set thecontainerView in the prepareForSegue:sender: method. For example:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([segue.identifier isEqualToString:@"SEGUE_IDENTIFIER"])
    {
        iOS5EmbedSegue * embedSegue = (iOS5EmbedSegue *)segue;
        embedSegue.containerView = self.containerView;
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment