Search code examples
swift2transitiondismisspresentviewcontroller

Swift2: Dismiss current view controller and show new view controller


I want to dismiss current view controller and show new view controller.

For example, a chatting application needs view controller for making chat room.

Let main view controller is A and view controller making chat room is B and chatting room is C.

When make new chat room, I have to go B and create then automatically present C. But when I dismiss C, I want to go A not B.

You may say "Oh, unwind can solve your problem!", but that's not I want.
I want to delete useless middle viewcontroller B.

And I saw article below

How to dismiss the current ViewController and go to another View in Swift

But for me, it doesn't work. It just dismiss or just present new view controller or present view controller and dismiss it as soon as show it.

Please help me!


Solution

  • If I correct understand, you can save A controller reference for example in AppDelegate:

        var ANavigationController: UINavigationController?
    

    and then create custom segue, where destination controller will be ANavigationController