Reputation: 14337
I would like to create my own UIStoryBoard and force the system to use it (inspired by Jody's answer).
How can I do it?
Creating a class @interface MyStoryboard : UIStoryboard
is not being invoked.
Upvotes: 8
Views: 1178
Reputation: 727047
You were on the right path subclassing UIStoryboard
: all you need to do now is to plug it into your application. The simplest way of doing it is in your application delegate's application:didFinishLaunchingWithOptions:
method:
MyStoryboard.h
@interface MyStoryboard : UIStoryboard
-(id)instantiateViewControllerWithIdentifier:(NSString *)identifier;
@end
MyStoryboard.m
@implementation MyStoryboard
-(id)instantiateViewControllerWithIdentifier:(NSString *)identifier {
NSLog(@"Instantiating: %@", identifier);
return [super instantiateViewControllerWithIdentifier:identifier];
}
@end
MyAppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];
UIStoryboard *storyboard = [MyStoryboard storyboardWithName:@"<identifier-of-your-storyboard>" bundle:nil];
self.window.rootViewController = [storyboard instantiateInitialViewController];
[self.window makeKeyAndVisible];
return YES;
}
With this code in place, you will see calls of NSLog
every time the instantiateViewControllerWithIdentifier:
method is called.
Upvotes: 10