Xcode11之后Main.StoryBoard和SceneDelegate的移除与使用

本文详细介绍了在Xcode11及以上版本中如何使用Main.StoryBoard以及不使用时的替代步骤,以及SceneDelegate的使用方法和不使用时的配置调整。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、Main.StoryBoard的使用

1、使用Main.StoryBoard(Default)

无需特殊处理,Xcode 11及其以上版本,默认生成用’Main.StoryBoard’模板

2、不使用Main.StoryBoard

  • a、在info.plist文件中找到Storyboard Name键值对,将其移除
    在这里插入图片描述
  • b、在TARGETS->info下找到Main storyboard file base name键值对,将其移除
    在这里插入图片描述
  • c、删除Main.storyboard
  • d、在侧边栏TARGETS->General下,找到Deployment Info项,在Status Bar Style选项中,勾选Supports multiple windows选项

二、SceneDelegate的使用

1、项目中使用SceneDelegate

  • a、打开SceneDelegate.m文件,在scenewillConnectToSession代理方法中,创建window窗口,初始化rootViewController
    -(void)scene:(UIScene*)scenewillConnectToSession:(UISceneSession*)sessionoptions:(UISceneConnectionOptions*)connectionOptions {
    UIWindowScenewindowScene = (UIWindowScene)scene;
    self.window= [[UIWindowalloc]initWithWindowScene:windowScene];
    self.window.frame = windowScene.coordinateSpace.bounds;
    self.window.rootViewController = ViewController.new;
    [self.window makeKeyAndVisible];
    }

2、 项目中不使用SceneDelegate

  • a、在info.plist文件中找到Application Scene Manifest键值对,将其移除
    在这里插入图片描述
  • b、在AppDelegate.m文件,移除UISceneSession lifecycle代理方法, 即application configurationForConnectingSceneSession 和applicationdidDiscardSceneSessions两个方法
    #pragma mark - UISceneSession lifecycle
    -(UISceneConfiguration *)application:(UIApplication *)application configurationForConnectingSceneSession:(UISceneSession *)connectingSceneSession options:(UISceneConnectionOptions )options {
    // Called when a new scene session is being created.
    // Use this method to select a configuration to create the new scene with.
    return[[UISceneConfigurationalloc]initWithName:@"Default Configuration"sessionRole:connectingSceneSession.role];
    }
    -(void)application:(UIApplication
    )applicationdidDiscardSceneSessions:(NSSet *)sceneSessions {
    // Called when the user discards a scene session.
    // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
    // Use this method to release any resources that were specific to the discarded scenes, as they will not return.
    }
  • c、AppDelegate.h文件,新增window属性
    @property (strong, nonatomic) UIWindow *window;
  • d、AppDelegate.m文件中,在applicationdidFinishLaunchingWithOptions代理方法中,创建window窗口,初始化rootViewController
    -(BOOL)application:(UIApplication*)applicationdidFinishLaunchingWithOptions:(NSDictionary*)launchOptions {
    // Override point for customization after application launch.
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    self.window.backgroundColor = UIColor.whiteColor;
    self.window.rootViewController = [[UINavigationController alloc]initWithRootViewController:[[ViewController alloc]init]];
    [self.window makeKeyAndVisible];
    return YES;
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值