I have manually setup a root view controller for iOS 13 using Xcode 11, Beta 5. Deleted references to main in the deployment info including removing reference to main in info.plist which I never found myself having to do prior to iOS 13. Setup for window is done in SceneDelegate, nested in willConnectTo function. Normally the app would crash if I missed a step. Now I'm getting a blank black screen instead of seeing what my view controller is setup for, say a red background. All of this use to work prior to beta 5.
Have performed erase all content and settings on the simulator. Cleared the build folder and have ran the app on a physical device. Also have used another computer with Xcode 11, beta 5. All results to the same blank black screen. What am I missing?
Here is my manual setup for root view controller in SceneDelegate file nested in willConnectTo function:
let viewCon = ViewController()
window = UIWindow(frame: UIScreen.main.bounds)
window?.rootViewController = viewCon
window?.makeKeyAndVisible()
To ensure you see your root view controller in iOS 13 when everything is done programmatically, you must do the following:
In the scene delegate, you must create the window instance and the root view controller:
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
guard let winScene = (scene as? UIWindowScene) else { return }
// Create the root view controller as needed
let vc = ViewController()
let nc = UINavigationController(rootViewController: vc)
// Create the window. Be sure to use this initializer and not the frame one.
let win = UIWindow(windowScene: winScene)
win.rootViewController = nc
win.makeKeyAndVisible()
window = win
}
}
Your Info.plist has to have the "Application Scene Manifest" entry. Below it should be the "Enable Multiple Windows" entry. Set to YES or NO as appropriate to your app. Optionally you should also have the "Scene Configuration" entry.
All of these entries are added by Xcode when you check the "Supports multiple windows" setting on the General tab of your target. This will default the "Enable Multiple Windows" entry to YES so you can change that to NO if you want scenes but not multiple windows.
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
guard let windowScene = (scene as? UIWindowScene) else { return }
let window = UIWindow(windowScene: windowScene)
self.window = window
let mainstoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let newViewcontroller:UIViewController = mainstoryboard.instantiateViewController(withIdentifier: "YourVCName") as! YourVCName
navigationController = UINavigationController(rootViewController: newViewcontroller)
window.rootViewController = navigationController
window.makeKeyAndVisible()
}
try this code!! if you are using ios 13 and your xcode is updated then you should set your root view controller in scene delegate instead of app delegate.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With