Segue Out of Navigation Controller

Segue Out of Navigation Controller

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"
Sample Image

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.

Swift - Permanent View Controller Segue (outside of Navigation Controller)

You can either change rootViewController of your main window:

self.window.rootViewController = vc

or you can just simply set vc's modalPresentationStyle to fullscreen (this doesn't have a "go back" option by itself, only you can dismiss it calling dismiss)


let vc = UIViewController()
vc.modalPresentationStyle = .fullScreen

or from storyboard change it's presentation style to fullscreen.

Get out of Navigation Controller with Segue

It sounds like you presented the NavigationController with a modal segue.
If this is the case you can call dismiss when you are ready to go back to starting view controller.

dismiss(animated: true, completion: nil)

Swift Dismiss navigation controller after prepare for segue

If I understand your code correctly, you're adding another segue back to AddPhotoVC. So if while your app was running and you clicked the "Debug View Hierarchy" (down by the debugger controls in Xcode) you'd see that you now have another AddPhotoVC on top of the original one.

Instead of performing a segue from SelectPhotoVC to AddPhotoVC you may want to consider performing an Unwind Segue instead. This way you could pass the values you want and all the previous VCs would be dismissed.

Segue and navigation controller interaction

From your screen shot it seems that the issue might be you have the tabBarController inside a navigationController.

You should use the TabBarController as the root view controller (arrow should point to it) and it shouldn't be embedded inside the stack of a navigation controller specifically it shouldn't be a navigationController's rootVC.

Read here Apple -NavigationController rootViewController

rootViewController The view controller that resides at the bottom of
the navigation stack. This object cannot be an instance of the
UITabBarController class.

Your below comments said that you rearranged everything by setting the tabBarVC as root to the application (arrow pointing to it) but it still didn't work. It's hard to identify the issue.

You should use print statements to find out which nav controller is doing the pushing, it might help you arrow down the problem.

override func viewDidLoad() {
super.viewDidLoad()

// is this the very navController that has the tabBar as root or is this the one of the other ones?
print("viewDidLoad: \(navigationController?.viewControllers.description as Any)") // this should print everything currently on the stack
}

How to get rid of navigation controller and segue to a controller before it?

By dismissing the root view controller of your key window, you dismiss all view controllers and go back to youe login vc assuming it's the initial view controller.

UIApplication.sharedApplication().keyWindow?.rootViewController?.dismissViewControllerAnimated(true, completion: nil)

How to segue to the root of navigation controller in Swift?

If this is a separate flow to the rest of your app, you could create a new navigation controller for this flow.

Create a new navigationController with screen 1 as its rootViewController. Then set the navigationController as the initialViewController of that storyboard. Now this collection of screens will act as a self contained flow inside your main app. Doing this, you can simply call self.navigationController?.popToRootViewController(animated: true) inside the button on screen 4, to return to the first screen.




Also just FYI,

  • The reason the red segue has a back button to 4, is because a storyboard reference creates a new instance of the viewController. You are not returning to number 1 here, you are adding a new copy of screen 1 into the navigation stack.
  • I don't know if its just the drawing or not, but having 1 screen per storyboard is a waste. Storyboards were designed to have many screens inside each

unwind segue Xcode 10 swift with navigation controller not working

From your comments, I'm guessing that the problem is that there is no FavouritesTableViewController in the view controller hierarchy at the time that the Save button is pressed. You cannot unwind to something that isn't already present: "unwind" means go back to something that was instantiated earlier and remains present, above the current view controller in the view controller hierarchy.

For example, let's say we have

UINavigationController -> (root view controller) -> FavouritesTableViewController
-> (push) ExplorationResultViewController

Now we can unwind from the Exploration controller to the Favourites controller, because the Favorites controller is already in the hierarchy before the Exploration controller. It sounds like maybe you are not appreciating that fact.



Related Topics



Leave a reply



Submit