main.stroyboard を削除した後、実行時にエラーが報告される
Thread 1: "-[AppDelegate setWindow:]: unrecognized selector sent to instance
また
Thread 1: "Could not find a storyboard named 'Main' in bundle NSBundle
解決:
1. プロジェクトの「ビルド設定」を開きます。
上図のように、「UIKit Main Storyboard File Base Name」のmainを削除します。
2.「info.plist」に移動し、「ストーリーボード名」を削除します。ここで「Delegateクラス名」の設定に注意してください。このときは「SceneDelegate」クラスを使用します。UIWindowを実装する場合はSceneDelegateクラスにコードを記述する必要があります。
3. この時点では、実行時にエラーは発生しませんが、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の内容です。