Skip to content

Instantly share code, notes, and snippets.

@kawanet
Created December 22, 2013 16:45
Show Gist options
  • Save kawanet/8085209 to your computer and use it in GitHub Desktop.
Save kawanet/8085209 to your computer and use it in GitHub Desktop.
instantiateWithStoryboard 前提として、Storyboard IDとクラス名を揃えておく。以下のカテゴリを使うと、文字列指定でなくて、クラス指定任意の画面を取り出せるようになる。
#import <UIKit/UIKit.h>
@interface UIViewController (Util)
// Usage:
// FOOViewController *vc = [FOOViewController instantiateWithStoryboard:self.storyboard];
// [self.navigationController pushViewController:vc animated:YES];
+ (instancetype)instantiateWithStoryboard:(UIStoryboard *)storyboard;
@end
#import "UIViewController+Util.h"
@implementation UIViewController (Util)
+ (instancetype)instantiateWithStoryboard:(UIStoryboard *)storyboard
{
return [storyboard instantiateViewControllerWithIdentifier:NSStringFromClass(self)];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment