Xcode11以后,Objective-C纯代码设置首页

2021-11-08  本文已影响0人  王煜仁

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];
    
}
上一篇下一篇

猜你喜欢

热点阅读