如何从Storyboard中加载View Controller?
1. 首先了解下UIStoryboard类:
@class UIViewController; @interface UIStoryboard : NSObject { } + (UIStoryboard *)storyboardWithName:(NSString *)name bundle:(nullable NSBundle *)storyboardBundleOrNil; - (UIViewController *)instantiateInitialViewController; - (UIViewController *)instantiateViewControllerWithIdentifier:(NSString *)identifier; @end
2. 从Storyboard中加载View Controller的方法:
//获取storyboard UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]]; //实例化箭头指向的ViewController ViewController *rootVC = [storyboard instantiateInitialViewController]; //根据storyboard ID实例化其中的ViewController // ViewController *rootVC = [storyboard instantiateViewControllerWithIdentifier:@"ViewController"];