0

I am trying to present VC after user is logged in. But after login is successful the VC turns black. Demonstration what happens is here and there are same images. I have found articles here on stackoverflow but any of them did not help me.enter image description hereenter image description hereenter image description hereenter image description hereenter image description here

Jason Krowl
  • 84
  • 2
  • 15
  • `ALMainController()` is equal to `ALMainController.init` and NOT "ALMainController.initTheOneSetWithAllTheOutletsAndConstraintsInTheStoryboard". Check that: https://stackoverflow.com/questions/24035984/instantiate-and-present-a-viewcontroller-in-swift – Larme Jun 20 '17 at 14:16

2 Answers2

0

try this code :

    let storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
    let vc: ALMainController = storyboard.instantiateViewController(withIdentifier: "ALMainController") as! ALMainController

    self.present(vc, animated: true, completion: nil)

Or you can use this:

    let firstPage = self.storyboard?.instantiateViewController(withIdentifier: "ALMainController")as! ALMainController
    let appDelegate = UIApplication.shared.delegate
    appDelegate?.window??.rootViewController = firstPage

Both should work.

And do not forget to write: "ALMainController" to your storyboard Id.

enter image description here

Let me know if it worked. :)

0ndre_
  • 3,577
  • 6
  • 26
  • 44
0

So the problem is that you are just initialising the ALMainController class.

However, this will not load your view from the Storyboard. There are 2 ways to do that properly and present that controller.

  1. In code by doing something like the following, given that this controller has an identifier like: "ALMainController"

let storyboard = UIStoryboard(name: "Main", bundle: nil) let controller = storyboard.instantiateViewController(withIdentifier: "ALMainController")
self.present(controller, animated: true, completion: nil)

  1. By creating a Segue in storyboard originating from the "Login controller" going towards the "ALMainController". You give that segue an identifier (EX: "goToMain") and call that in your code doing something like the following

self.performSegue(withIdentifier: "goToMain", sender: self)

Hope that helps!