Open View Controller on button click in iOS with Swift 5

Open View Controller on button click in iOS with Swift 5
May 23, 2020 No Comments Development,iOS Development Pushpendra Kumar

This tutorial, is about Open new View Controller on button click in ios with Swift 5. This is the basic example of a beginner or for those who are looking for this topic. With the help of this tutorial you can easily understand the complete flow. And you can easily understand that, how you can open your new view controller on click event. In this complete tutorial I have told you two procedures to open a new screen on button click. So follow the complete tutorial and understand the complete flow.

Open New View Controller

So, In this tutorial. I have explained to you about how you can move from one controller to another in a swift 5 programming language. So I have tried to explain to you the complete scenario.

So, I hope you have seen the complete video. And It seems that you have to understand the complete video. If you have any doubts in that please comment below into the comment box. After that I am providing you the related code for this tutorial.

First Method for open new view controller in swift 5

//MARK: FIRST METHOD TO OPEN NEW CONTROLLER
@objc func tapOnButton(){
      let story = UIStoryboard(name: "Main", bundle: nil)
      let controller = story.instantiateViewController(identifier: "SecondController") as! SecondController
      self.present(controller, animated: true, completion: nil)
  }

After that, I will tell you about the second method for New View Controller.

Second Method for open new view controller in swift 5

//MARK: SECOND METHOD FOR OPEN NEW VIEW CONTROLLER IN SWIFT 5
@objc func tapOnButtonForNavigation(){
      let story = UIStoryboard(name: "Main", bundle: nil)
      let controller = story.instantiateViewController(identifier: "SecondController") as! SecondController
      let navigation = UINavigationController(rootViewController: controller)
      self.view.addSubview(navigation.view)
      self.addChild(navigation)
      navigation.didMove(toParent: self)
 }

Very good, After that, I will tell you another method. If you have existing navigation controller. Then you can use below method. For your information I would like to tell you that, This information is not available in the entire video.

Third Method

//MARK: 3rd METHOD FOR OPEN NEW VIEW CONTROLLER
@objc func tapforNewNavigation(){
      let story = UIStoryboard(name: "Main", bundle: nil)
      let controller = story.instantiateViewController(identifier: "SecondController") as! SecondController
      self.navigationController?.pushViewController(controller, animated: true)
  }

Great, You have complete the tutorial. Now If you have any doubt then please comment into the comment box. πŸ˜ŠπŸ˜ŠπŸ˜ŠπŸ‘‡πŸ»πŸ‘‡πŸ»πŸ‘‡πŸ»πŸ‘‡πŸ»πŸ‘‡πŸ»

In Conclusion, You have done with this tutorial. And hope now the concept of Open new View Controller on button click in iOS with Swift 5. If you have any doubts regarding the Open New View Controller on button click in iOS with Swift 5 then you can comment into the comment box. And if you like this tutorial with a complete description of the simple and attractive tutorial in iOS then pleaseΒ like my videoΒ on YouTube and do not forget to subscribe to myΒ YouTube channel. Because you will get lots of videos related to swift development with very sort tricks.

Besides, If you are more curious about the development and knowing about tutorials then follow the below links πŸ‘‡πŸ»πŸ‘‡πŸ»πŸ‘‡πŸ»πŸ˜Ž

Tags
About The Author
Pushpendra Kumar I am passionate about mobile application development and professional developer at Colour Moon Technologies Pvt Ltd (www.thecolourmoon.com). This website I have made so that I can meet with new challenges and can share here.

Leave a reply

Your email address will not be published. Required fields are marked *