Skip to content

Instantly share code, notes, and snippets.

@tomohisa
Created July 30, 2014 10:07
Show Gist options
  • Save tomohisa/bee735038bf89acd3202 to your computer and use it in GitHub Desktop.
Save tomohisa/bee735038bf89acd3202 to your computer and use it in GitHub Desktop.
Storyboard by viewController factory method
#import <UIKit/UIKit.h>
@interface UIViewController (JTCAddition)
+(instancetype) viewControllerFromSameNameStoryboard;
+(UINavigationController*) viewControllerFromSameNameStoryboardInNavigationController;
@end
#import "UIViewController+JTCAddition.h"
@implementation UIViewController (JTCAddition)
+(instancetype) viewControllerFromSameNameStoryboard {
UIStoryboard * storyboard = [UIStoryboard storyboardWithName:NSStringFromClass(self) bundle:nil];
if (!storyboard) {
return nil;
}
return [storyboard instantiateInitialViewController];
}
+(UINavigationController*) viewControllerFromSameNameStoryboardInNavigationController {
UINavigationController * nav = [[UINavigationController alloc] initWithRootViewController:[self viewControllerFromSameNameStoryboard]];
return nav;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment