Segue Out of Navigation Controller

会有一股神秘感。 提交于 2019-12-10 02:58:35

问题


I am trying to leave the initial view controller, and go into the blank view controller. That is fine, but that would make the blank view controller also part of the navigation controller, which is not what I want. I want to segue out of the view controller.

In the view controller I try to segue out of, it pops it self, and when I try the method in the view will appear of the target view controller, self.navigationController?.topViewController returns itself, but self.navigationController?.popViewControllerAnimated(animated) doesn't work


回答1:


If you have a navigationController do

self.navigationController?.popViewControllerAnimated(false)

Otherwise do

self.dismissViewControllerAnimated(false, completion: nil)

Update

Go to your Storyboard, select the ViewController you want to navigate to and add a storyboard id. Make sure the click "Use Storyboard ID"

Go to the class you want to navigate from and add the following code

let storyboard = UIStoryboard(name: "Main", bundle: nil)
// vc is the Storyboard ID that you added
// as! ... Add your ViewController class name that you want to navigate to
let controller = storyboard.instantiateViewControllerWithIdentifier("vc") as! ViewController
self.presentViewController(controller, animated: true, completion: { () -> Void in
})

Add this code in the action that you use when you want to navigate.




回答2:


I believe this can be done without having to write any code at all. To Segue out of a Navigation Controller follow these steps:

  1. Create a Segue from the View Controller that has a Navigation Controller as it's root view controller to the View Controller that you would like to go to next (without being inside the Navigation Controller)
  2. Click on the new Seque
  3. Open the Attributes Inspector
  4. Choose 'Kind' -> 'Present Modally'
  5. Choose 'Present' -> 'Over Current Context'



来源:https://stackoverflow.com/questions/34458633/segue-out-of-navigation-controller

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!