删除main.stroyboard后,运行时报错
Thread 1: "-[AppDelegate setWindow:]: unrecognized selector sent to instance
或者
Thread 1: "Could not find a storyboard named 'Main' in bundle NSBundle
解决办法:
1. 打开项目的“Build Settings”
如上图,将“UIKit Main Storyboard File Base Name”中的main删除。
2. 进入到“info.plist”中,将“Storyboard Name”删除。此处注意“Delegate Class Name”的设置,此时使用“SceneDelegate” class,在实现UIWindow时,代码需要写在SceneDelegate class中。
3. 这个时候运行已经不报错了,但是整个app都是黑色,原因是没有加载UIWindow。
4. 在SceneDelegate.m文件中添加UIWindow的实现
- (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions {
// Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
// If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
// This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
UIWindowScene *windowScene = (UIWindowScene*)scene;
self.window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]];
[self.window setWindowScene: windowScene];
ViewController *viewController = [[ViewController alloc] init]; // need import ViewController.h head file
[self.window setRootViewController: viewController]; // set root view controller
[self.window makeKeyAndVisible]; // show it
}
此时显示的是ViewController中的内容。