Created
September 2, 2014 06:14
-
-
Save krin-san/c9d5c79c22249378bd8e to your computer and use it in GitHub Desktop.
CrossStoryboardSegue
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
// | |
// CrossStoryboardSegue.h | |
// | |
#import <UIKit/UIKit.h> | |
@interface CrossStoryboardSegue : UIStoryboardSegue | |
// Default: YES | |
@property (nonatomic, assign) BOOL animatedSegue; | |
+ (UIViewController *)sceneNamed:(NSString *)identifier; | |
@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
// | |
// CrossStoryboardSegue.m | |
// | |
#import "CrossStoryboardSegue.h" | |
@implementation CrossStoryboardSegue | |
#pragma mark - Initializing | |
- (id)initWithIdentifier:(NSString *)identifier | |
source:(UIViewController *)source | |
destination:(UIViewController *)destination { | |
self = [super initWithIdentifier:identifier source:source destination:[[self class] sceneNamed:identifier]]; | |
if (self) { | |
self.animatedSegue = YES; | |
} | |
return self; | |
} | |
+ (UIViewController *)sceneNamed:(NSString *)identifier { | |
NSArray *info = [identifier componentsSeparatedByString:@"@"]; | |
NSAssert(info.count == 2, @"Invalid CrossStoryboardSegue identifier format"); | |
NSString *sceneID = info[0]; | |
NSString *storyboardName = info[1]; | |
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:storyboardName bundle:nil]; | |
UIViewController *scene = nil; | |
if (sceneID.length == 0) { | |
scene = [storyboard instantiateInitialViewController]; | |
} else { | |
scene = [storyboard instantiateViewControllerWithIdentifier:sceneID]; | |
} | |
return scene; | |
} | |
#pragma mark - Storyboard | |
- (void)perform { | |
UIViewController *source = (UIViewController *)self.sourceViewController; | |
if ([self.destinationViewController isKindOfClass:[UINavigationController class]]) { | |
[source.navigationController presentViewController:self.destinationViewController animated:self.animatedSegue completion:nil]; | |
} else { | |
[source.navigationController pushViewController:self.destinationViewController animated:self.animatedSegue]; | |
} | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment