I have authorization window. When app is starting it is okey. I tap sign in and go to the next window. But when I tap sign out and want to back at authorization window - I get nil. In the method signinView controller is nil.
Asked
Active
Viewed 1,701 times
-3
-
2Please post your [mcve] as text marked up as code and not a picture. Making it a picture prevents us from copying and pasting the code and diminishes our ability to help you. – NathanOliver Jul 11 '16 at 13:09
-
you provide huge amount of information , we can't just assume that how you showing your view controller . please post code – Prashant Tukadiya Jul 11 '16 at 13:09
-
The most important thing is that you shouldn't access storyboard like this: `self.window?.rootViewController!.storyboard?`. This is the worst approach i have ever seen. if anything is nil, either application will crash (to unwrap) – Asif Bilal Jul 12 '16 at 08:05
2 Answers
8
you need to take instance from Storyboard.
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let controller = storyboard.instantiateViewControllerWithIdentifier(“MyController”)
In this way you will get your controller instance.
Make sure you already set storyboard ID for this controller.

Bilawal Liaqat
- 178
- 4
-
I met this when I'm mixed to use IB and coding programmatically. In some pure code VC, I need to declare the storyboard then to instantiate another VC, otherwize that vc will not be opened. – Zhou Haibo Jun 24 '21 at 08:52
1
Just replace below code in function's second line and hope it will solved your problem.
let storyboard = UIStoryboard(name: "Main", bundle: nil)//Make it global
let controller = storyboard!.instantiateViewControllerWithIdentifier("your identifer")

Amit Jagesha シ
- 1,092
- 12
- 21