Hello! I've been using Objective-C to write a single-view application and have been using AppDelegate for my window setup.
However, with the next release of iOS, I need to adopt SceneDelegate into my app for it to work.
I'm having trouble getting my main ViewController to show up when the app starts. It just shows up as a black screen.
I built this app entirely programmatically. When I go into my info.plist
file, I have everything but the Storyboard setup since, obviously, I don't have one.
I've left my code below.
Thank you!
My current AppDelegate:
#import "ViewController.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
#pragma mark - UISceneSession Configuration
- (UISceneConfiguration *)application:(UIApplication *)application configurationForConnectingSceneSession:(UISceneSession *)connectingSceneSession options:(UISceneConnectionOptions *)options {
// Create the configuration object
return [[UISceneConfiguration alloc] initWithName: @"Default" sessionRole: connectingSceneSession.role];
}
#pragma mark - Application Configuration
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
return YES;
}
- (void) dealloc {
[super dealloc];
}
@end
My Current SceneDelegate:
#import "SceneDelegate.h"
#import "ViewController.h"
@interface SceneDelegate ()
@end
@implementation SceneDelegate
- (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions {
// Ensure we have a UIWindowScene
if (![scene isKindOfClass:[UIWindowScene class]]) {
return;
}
UIWindowScene *windowScene = (UIWindowScene *)scene;
// Create and attach the window to the provided windowScene
self.window = [[UIWindow alloc] initWithWindowScene:windowScene];
// Set up the root view controller
ViewController *homeViewController = [[[ViewController alloc] init] autorelease];
UINavigationController *navigationController = [[[UINavigationController alloc] initWithRootViewController: homeViewController] autorelease];
// Present the window
self.window.rootViewController = navigationController;
[self.window makeKeyAndVisible];
}
@end