Created
June 14, 2013 01:35
-
-
Save stephsharp/5778803 to your computer and use it in GitHub Desktop.
Embed Segue for iOS5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// iOS5EmbedSegue.h | |
// Created by Stephanie Sharp on 2/05/13. | |
// | |
#import <UIKit/UIKit.h> | |
@interface iOS5EmbedSegue : UIStoryboardSegue | |
@property (nonatomic, strong) UIView * containerView; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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 |
- If you do not set the
containerView
property, it will default to thesourceViewController
'sview
. Otherwise, the segue will embed thedestinationViewController
in thecontainerView
. - 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
first Question. why did you took sourceViewController's view as containerView is it is not there..?
second. Is there any way from storyboard to say that this is the container view.?