XCode新建空白工程后,手工增加Storyboard并添加ViewController后,只显示空白,不显示ViewController:
调试时会提示:
Application windows are expected to have a root view controller at the end of application launch
这时,需要手工修改一处代码和一处配置:
1、AppDelegate源码文件
//修改前 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; // Override point for customization after application launch. self.window.backgroundColor = [UIColor whiteColor]; [self.window makeKeyAndVisible]; return YES; } //修改后 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { return YES; }
2、指定启动的Storyboard
在Project-》Targets-》Summary中修改Main Storyboard属性为新添加的Storyboard名称(不带后缀)。
或者
修改XXX-Info.plist文件,添加属性
<key>UIMainStoryboardFile</key> <string>Storyboard名称(不带后缀)</string>
然后就OK啦。