Issue
I am trying to convert (slowly mordenize) an old iOS project to support UISceneDelegate. However at the moment the old appdelegate creates a UIWindow and attaches a UIViewController to the windows rootViewController in the finishedLaunching.
As I am not ready to convert my application to Storyboards yet is there a way I can achieve the same result using UISceneDelegate ?
Please note the mainViewController is not backed by a XIB or a storyboard so there is no reference to any UI Files in the UIWindowSceneSessionRoleApplication portion of my info.plist
Regards Christian Stœr Andersen
Solution
Implement the following method in your UIWindowSceneDelegate
subclass to assign your UIViewController
:
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
guard let windowScene = scene as? UIWindowScene else {return}
self.window = UIWindow(windowScene: windowScene)
self.window!.rootViewController = YourViewController() // Instantiate your UIViewController
self.window!.makeKeyAndVisible()
}
With objective-c:
- (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions {
self.window = [[UIWindow alloc] initWithWindowScene:(UIWindowScene *)scene];
self.window.rootViewController = [[YourViewController alloc] init];
[self.window makeKeyAndVisible];
}
Answered By - RedWheelbarrow
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.