今天新写一个项目,不需要Storyboard,本以为很简单,删除之后黑屏踩了一个坑,在此记录一下。这个解决办法不一定是正确,但是这么做确实可行。

第一步
选中Main.storyboard删除

第二步
Main Interface 删除Main
请添加图片描述
第三步
info.plist
Application Scene Manifest 点减号删除
请添加图片描述
第四步
删除SceneDelegate文件请添加图片描述
第五步
AppDelegate 文件注释或删除以下代码
#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 [[UISceneConfiguration alloc] initWithName:@"Default Configuration" sessionRole:connectingSceneSession.role];
}


- (void)application:(UIApplication *)application didDiscardSceneSessions:(NSSet<UISceneSession *> *)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.
}

第六步
给AppDelegate添加属性window

    var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    // Override point for customization after application launch.
    window = UIWindow.init()
    window?.frame = UIScreen.main.bounds
    //window?.backgroundColor = UIColor.red
    window?.rootViewController = ViewController()
    window?.makeKeyAndVisible()
    return true
}

更多推荐