0

So when I click on a button from another View Controller, it is suppose to present the next View Controller. However, when clicking the button, it just show the next View Controller with a black screen, even though there is content on it. How do I fix this?

I do know that there had already been similar questions asked but none helped me in solving this issue.

Button clicked code:

@IBAction func onSignUp(_ sender: Any) {
    presentDetail(SignUpViewController())
}

Present next View Controller and animation code:

   extension UIViewController {


        func presentDetail(_ viewControllerToPresent: UIViewController) {
            let transition = CATransition()
            transition.duration = 0.25
            transition.type = CATransitionType.push
            transition.subtype = CATransitionSubtype.fromRight
            self.view.window!.layer.add(transition, forKey: kCATransition)

            self.present(viewControllerToPresent, animated: false)
        }

        func dismissDetail() {
            let transition = CATransition()
            transition.duration = 0.25
            transition.type = CATransitionType.push
            transition.subtype = CATransitionSubtype.fromLeft
            self.view.window!.layer.add(transition, forKey: kCATransition)

            dismiss(animated: false)
        }



}

To clarify, the presentDetail function suppose to present the next View Controller with an animation (From Right), as shown in the code.

Andy
  • 169
  • 10

1 Answers1

1

You need to instantiate the target ViewController from Storyboard before presenting it.

@IBAction func onSignUp(_ sender: Any) {

presentDetail(

storyboard?.instantiateViewController(withIdentifier: "putyourIdentifierhere"))
}

instantiateViewController function returns the Viewcontroller you want to present.

burnsi
  • 6,194
  • 13
  • 17
  • 27
  • Doing that results in a black screen still. I put the above code right before presentDetail. And the Storyboard ID is put instead of "putyourIdentifierhere" – Andy Jan 05 '19 at 20:01
  • Updated my answer. Does your code look like this. Please update your question. – burnsi Jan 05 '19 at 20:05