Opening viewController programmatically in swift

后端 未结 3 1774
粉色の甜心
粉色の甜心 2021-02-07 13:27

I want to open new UIViewController on the button through code. I have already made the controller in storyboard and just want to link it and also I don\'t want to use XIB inter

相关标签:
3条回答
  • 2021-02-07 13:44
    self.navigationController!.pushViewController(self.storyboard!.instantiateViewControllerWithIdentifier("userProfileController") as UIViewController, animated: true)
    

    I wanted to add my view controller to the navigation controller and this also worked

    0 讨论(0)
  • 2021-02-07 13:53

    To open New view controller you need to write this line in button click event:

    self.performSegueWithIdentifier("GoToViewController", sender:self)
    

    To link up with new view controller follow this steps:

    • Select New view controller from storyboard & right click on it

    • You will find Dark dray popup will appear (see image )

    • Now under Presenting Segues select Present Modally & drag to the View controller from where you need to open up this view controller & link it

    • You will find new segue created under New view controller

    • Now select that segue go to inspector & copy the identifier or rename & copy it

    • Use that identifier in above line

    Hope it will work.

    enter image description here

    0 讨论(0)
  • 2021-02-07 13:56

    For swift 4.2, try the following code:

    self.navigationController!.pushViewController(self.storyboard!.instantiateViewController(withIdentifier: "inventoryViewController") as UIViewController, animated: true)
    
    0 讨论(0)
提交回复
热议问题