1

I am trying to transit to another ViewController but it gives me black screen! There is my code:

                            if (content == nil) {
                            let sec: testViewController = testViewController(nibName: nil, bundle: nil)
                            self.present(sec, animated: true, completion: nil)
                        }

in Storyboard: enter image description here

3 Answers3

1

Give Storyboard ID to testViewController from the Main Storyboard.

if content == nil {
    let storyboard = UIStoryboard(name: "Main", bundle: nil)
    let sec: testViewController = storyboard.instantiateViewController(withIdentifier: "testViewController") as! testViewController
    self.present(sec, animated: true, completion: nil)
    }
Sanjay Shah
  • 502
  • 2
  • 13
1

In Storborad give storyboard Id ex-->testViewControllerId and check UseStoryboard Id

let storyboard = UIStoryboard(name: "Main", bundle: nil)
let testController = storyboard.instantiateViewController(withIdentifier :"testViewControllerId") as! testViewController
self.present(testController, animated: true)
Lalit kumar
  • 1,797
  • 1
  • 8
  • 14
0

You just want to try another way to programmatically present your destination ViewController. Try this one,

let storyBoard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil) 
let myViewController: UIViewController = storyBoard.instantiateViewControllerWithIdentifier("<myViewControllerRestorationID>") //if you have the restoration ID, otherwise use 'ModalViewController'
self.presentViewController(myViewController, animated: true, completion: nil)
Vignesh Davins
  • 285
  • 1
  • 13