Xcode 14 delete main.stroyboard to solve the problem of startup failure

After deleting main.stroyboard, an error is reported when running

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

or

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

Solution:

1. Open the project's "Build Settings"

As shown above, delete main in "UIKit Main Storyboard File Base Name".

2. Go to "info.plist" and delete "Storyboard Name". Pay attention to the setting of "Delegate Class Name" here. At this time, use the "SceneDelegate" class. When implementing UIWindow, the code needs to be written in the SceneDelegate class.

3. At this time, there is no error when running, but the whole app is black, because the UIWindow is not loaded.

4. Add the implementation of UIWindow in the SceneDelegate.m file

- (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
}

What is displayed at this time is the content in ViewController.

Guess you like

Origin blog.csdn.net/leon_founder/article/details/127347582