美文网首页ios系统兼容
详解SceneDelegate和Man.storyboard的删

详解SceneDelegate和Man.storyboard的删

作者: 逆风g | 来源:发表于2021-08-31 17:21 被阅读0次

    自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/ddvziltx.html