
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Navigate from One View Controller to Another in iOS
To navigate from one view Controller to another view Controller in iOS, we need to use Navigation controller. Navigation controller manages a stack of View controller when we go from one view to another view.
Navigation from one view controller to another view controller can be done like mentioned below.
Step 1 − Create a View controller object.
let vc = self.storyboard?.instantiateViewController(withIdentifier: "VC2ViewController") as! VC2ViewController
In this step we initialize an object of the type of our another view controller, to which we want to navigate. The identifier variable should be same as the identifier of our second view controller.
Step 2 − Navigating to Other View Controller
self.navigationController?.pushViewController(vc, animated: true)
In this step we navigate to the second view controller with help of our navigation controller. Here we are pushing the View controller. We can also present the other view controller instead of pushing it.
self.present(vc, animated: true, completion: nil)
When we run the above code on device we get the following result.