xcode 14 删除main.stroyboard启动失败的问题解决

删除main.stroyboard后,运行时报错

Thread 1: "-[AppDelegate setWindow:]: unrecognized selector sent to instance 

或者

Thread 1: "Could not find a storyboard named 'Main' in bundle NSBundle

解决办法:

1.  打开项目的“Build Settings”

如上图,将“UIKit Main Storyboard File Base Name”中的main删除。

2. 进入到“info.plist”中,将“Storyboard Name”删除。此处注意“Delegate Class Name”的设置,此时使用“SceneDelegate” class,在实现UIWindow时,代码需要写在SceneDelegate class中。

3. 这个时候运行已经不报错了,但是整个app都是黑色,原因是没有加载UIWindow。

4. 在SceneDelegate.m文件中添加UIWindow的实现

- (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).
    UIWindowScene *windowScene = (UIWindowScene*)scene;
    self.window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]];
    [self.window setWindowScene: windowScene];

    ViewController *viewController = [[ViewController alloc] init]; // need import ViewController.h head file
    [self.window setRootViewController: viewController];    // set root view controller
    [self.window makeKeyAndVisible];    // show it
}

此时显示的是ViewController中的内容。

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值