Saketram Durbha
Saketram Durbha

Reputation: 450

Segue Out of Navigation Controller

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

enter image description here

Upvotes: 9

Views: 3864

Answers (2)

Pete Varley
Pete Varley

Reputation: 412

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'

enter image description here

Upvotes: 5

Rashwan L
Rashwan L

Reputation: 38833

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" enter image description here

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.

Upvotes: 7

Related Questions