I changed the initial screen which is not on the Main
storyboard, I did exactly like it was written on google:
Changed from view controllers attribute inspector
is initial view controller
deleted the “Main storyboard file base name” line and the “Storyboard Name” line in
info
fileadded code below in scene delegate:
window = UIWindow(frame: windowScene.coordinateSpace.bounds)
window?.windowScene = windowScene
window?.makeKeyAndVisible()
let vc = LoginViewController() // view controller which must be the new one
window?.rootViewController = vc
I did all above but after running the xCode project I see only a black screen and an error Thread 1: Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value
this error is in LoginViewController
's textfield, I tried reAttaching IBOutlet
but it doesn't seem to work
any solutions ?
p.s. I don't know if it will be helpful to know, but LoginViewController
is fully copied with its own storyobard from another xCode project.
CodePudding user response:
The problem is this line:
LoginViewController()
This view controller has outlets, meaning that it is designed in the storyboard. What you want to do here is not to create a fresh LoginViewController, as you are doing, but to extract the desired LoginViewController instance from the storyboard.