Multiple way of navigating from one screen to another in iOS Swift

We are exploring multiple ways of navigating from one screen to another.

We are considering navigation by embedding navigation controller.

  1. Programatically

Consider we are moving from one screen to another (SecondViewController)

@IBAction func btnNext(_ sender: AnyObject) {
        
   let vc = self.storyboard?.instantiateViewController(withIdentifier: "SecondViewController") as! SecondViewController
   navigationController?.pushViewController(vc, animated: true)        
}

 2. Using direct segue from button 

Consider we have direct segue from button. In this case we can navigate from one screen to another without writing single line of code.

Screenshot 2019-12-25 at 4.51.09 PM.png

3. Using segue with identifier and created from viewcontroller 

@IBAction func btnNext(_ sender: AnyObject) {
   performSegue(withIdentifier: "moveNext", sender: self)        
}

Screenshot 2019-12-25 at 4.50.32 PM.png

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s