Richa Goyal
Richa Goyal

Reputation: 23

Calling a segue programatically in swift

I want to call a segue in swift on the condition that all the fields of the form are filled in. I tried using the following code :

 let vc = TargetViewController()
                        navigationController?.pushViewController(vc, animated: true )

I am not using a nib, and hence have tried to use this without the nib option. It opens a blank screen, but does not display the contents of the target view controller. Any help would be appreciated.

Upvotes: 0

Views: 196

Answers (2)

Saurabh Prajapati
Saurabh Prajapati

Reputation: 2380

You should try This

if(Your Condition)
    {
        var View:ViewController2 = self.storyboard?.instantiateViewControllerWithIdentifier("") as ViewController2
        self.navigationController?.pushViewController(View, animated: true)
    }

Upvotes: 0

mustafa
mustafa

Reputation: 15464

There is a method on UIViewController shouldPerformSegueWithIdentifier(_:sender:) use this to test if segue can be performed. And If not return false from this method.

Upvotes: 1

Related Questions