当我们在Xcode11中创建新项目时,会发现多了一个SceneDelegate的新类,这是iPadOS带来的新的多窗口支持的结果,并且有效地将应用程序委托的工作分成两部分。
在iOS 13中的新顶级对象是一个UIWindowScene。
当我们删除main.storyboard时,首先应该在Info.plist中删除相应的键值对。
target中的info里的Main storyboard项也要删除掉:
其次我们应该在SceneDelegate.m中写入新的window,而不是在以前的AppDelegate.m中写。
- (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).
self.window = [[UIWindow alloc] initWithWindowScene:(UIWindowScene*)scene];
ViewController *vc = [[ViewController alloc] init];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
self.window.rootViewController = nav;
//self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
}
注意:
这里写的alloc window时跟AppDelegate时写法不一样。