经常需要在故事板中获取我们指定的视图控制器,方法如下:
1.在故事板中为对应的ViewController设置一个Storyboard ID:
2.用代码获取:
self.window.rootViewController = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] // 在main bundle中(当bundle参数值设置为nil时)获取名为Main的故事板
instantiateInitialViewController]; // 在故事板中获取根视图控制器
self.window.rootViewController = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] // 在main bundle中(当bundle参数值设置为nil时)获取名为Main的故事板instantiateViewControllerWithIdentifier:@"ViewController_ID"];
instantiateViewControllerWithIdentifier:@"ViewController_ID"]; // 在故事板中获取Storyboard ID为ViewController_ID的视图控制器