答案 0 :(得分:10)
你在UIStoryboard
子类的正确路径上:你现在需要做的就是将它插入你的应用程序。最简单的方法是在您的应用程序委托application:didFinishLaunchingWithOptions:
方法:
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;
}
使用此代码后,每次调用NSLog
方法时,您都会看到instantiateViewControllerWithIdentifier:
的调用。