美文网首页
详解SceneDelegate和Man.storyboard的删

详解SceneDelegate和Man.storyboard的删

作者: 笑笑菜鸟 | 来源:发表于2022-03-08 15:16 被阅读0次

    紧接3.8特殊节日的文章Xcode 11新建项目,继续学习
    自xcode11新增SceneDelegate后,SceneDelegate与Man.storyboard该如何处理:

    1. 第一种情况,删除SceneDelegate,但保留Man.storyboard:

    • 删除info.plist中的Application Scene Manifest一项
    • 在AppDelegate.h中添加window属性@property (strong, nonatomic) UIWindow *window;
    • 删除AppDelegate.m中新增的两个UIScene方法
    • 删除UISceneDelegate类文件
      切记要在AppDelegate.h中添加window属性,否则Man.storyboard无法正常加载

    2. 第二种情况,删除SceneDelegate且删除Man.storyboard:

    • 删除info.plist中的Application Scene Manifest一项
    • 在AppDelegate.h中添加window属性@property (strong, nonatomic) UIWindow *window;}
    • 删除AppDelegate.m中新增的两个UIScene方法
    • 删除UISceneDelegate类文件

    • 删除Main.storeboaard文件
    • 项目TARGETS->General->Main Interface置为空
    • 删除info.plist中Main storyboard file base name一项
    • AppDelegate.m中导入目标头文件,在didFinishLaunchingWithOptions方法中添加目标类:
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
        // Override point for customization after application launch.
        self.window = [[UIWindow alloc] init];
        self.window.frame = [UIScreen mainScreen].bounds;
        self.window.backgroundColor = [UIColor whiteColor];
    
        ViewController * vc = [[ViewController alloc]init];
        self.window.rootViewController = vc;
        [self.window makeKeyAndVisible];
        return YES;
    }
    

    3. 第三种情况,保留SceneDelegate但删除Man.storyboard:

    • 项目TARGETS->General->Main Interface置为空
    • 删除info.plist中Main storyboard file base name一项
    • 删除info.plist中Application Scene Manifest -> Scene Configuration -> Application Scene Role -> Item 0 -> Storyboard name一项
    • SceneDelegate.m中导入目标头文件,在willConnectToSession方法中添加目标类:
    - (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions {
        if ([scene isKindOfClass:[UIWindowScene class]]) {
            UIWindowScene *windowScene = (UIWindowScene*)scene;
            self.window = [[UIWindow alloc] initWithWindowScene:windowScene];
            self.window.frame = [UIScreen mainScreen].bounds;
            self.window.backgroundColor = [UIColor whiteColor];
    
            ViewController * vc = [[ViewController alloc]init];
            self.window.rootViewController = vc;
            [self.window makeKeyAndVisible];
        }
        
    }
    

    相关文章

      网友评论

          本文标题:详解SceneDelegate和Man.storyboard的删

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