Xcode11发布之后,新建项目会有很多变化,最大的变化是多了SceneDelegate文件,此时使用纯代码设置页面,流程和以往会有一些不一样。如下
首先在Main.storyboard中取消勾选Is Initial View Controller,如下图
Main.storyboard其次在TARGETS中删除Main Interface,如下图
Main Interface最后在info.plist文件中删除这一项,如下图
info.plist注意,如果不做以上设置,运行后会出现如下图打印输出
打印输出
打开SceneDelegate.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).
UIWindowScene *windowScene = (UIWindowScene *)scene;
self.window = [[UIWindow alloc] initWithWindowScene:windowScene];
ViewController *vc = [[ViewController alloc] init];
self.window.rootViewController = vc;
[self.window makeKeyAndVisible];
}
网友评论