I am trying to set an initial root view controller programmatically using SceneDelegate in iOS 14 (no storyboard at all). I have followed https://medium.com/@sapa.tech/xcode-11-3-remove-storyboard-from-project-6c48c9d11123 to remove storyboard from my app, and have seen many answers to this question in swift in Why is manually setup root view controller showing black screen?, and Set root view controller iOS 13 and iOS 13: Swift - 'Set application root view controller programmatically' does not work. However, I am looking for tips on how to do it in objective C instead. So far, I have this in my scene delegate, where ViewController is the class I am trying to set as the root view controller:
- (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions {
UIWindowScene * winscene = [[UIWindowScene alloc]initWithSession:session connectionOptions:connectionOptions];
[self.window setWindowScene:winscene];
ViewController * viewController = [[ViewController alloc]init];
self.window.rootViewController = viewController;
[self.window makeKeyAndVisible];
}
And in my AppDelegate:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
return YES;
}
I have tried to translate the Swift answers I found to objective c but I still end up with a black screen on the simulator. The app builds fine with no error, but I just cannot get the ViewController to show up instead of a black screen. Does anyone know what I am missing?