iOS 11 删除 Main.storyboard替换为自定义xib

当我们在Xcode11中创建新项目时,会发现多了一个SceneDelegate的新类,这是iPadOS带来的新的多窗口支持的结果,并且有效地将应用程序委托的工作分成两部分。

 

在iOS 13中的新顶级对象是一个UIWindowScene。

当我们删除main.storyboard时,首先应该在Info.plist中删除相应的键值对。

target中的info里的Main storyboard项也要删除掉:

 

其次我们应该在SceneDelegate.m中写入新的window,而不是在以前的AppDelegate.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).
    self.window = [[UIWindow alloc] initWithWindowScene:(UIWindowScene*)scene];
    ViewController *vc = [[ViewController alloc] init];
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
    self.window.rootViewController = nav;
    //self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
}

注意:

这里写的alloc window时跟AppDelegate时写法不一样。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值