详解SceneDelegate和Man.storyboard的删除与保留关系

紧接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的删除与保留关系)