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

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

作者: 王煜仁 | 来源:发表于2021-11-08 13:50 被阅读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];
        
    }
    

    相关文章

      网友评论

          本文标题:Xcode11以后,Objective-C纯代码设置首页

          本文链接:https://www.haomeiwen.com/subject/tdmuzltx.html