Once I got a very unusual task for me. Along with finding the reasonable solution, I worried about the feasibility of it, since I couldn’t resolve this with a cut and dried scenario. So what exactly did I have to do?

Imagine we have three view controllers, where the first one is the main. The general idea is to display the third view controller after the first at once, but when the user pushes the “back” button it should display the second controller and only then you can return to the first.

It has to be clearer on the following scheme:

View controller scheme

The prescribed solution is that after pushing the “next” button on the first view controller, the third controller should contain action bar panel but the second shouldn’t also transition animation should work only for the third one and icing on the cake is that the second controller should be opened in fullscreen mode. To cut the story short, all manipulations with the second controller should be unnoticeable for user’s eyes.

We can devise it as follows:

@IBAction func onNext(sender: AnyObject) {
    //Create second View
    let secondVC = UIStoryboard(name: "Main", bundle: nil)
        .instantiateViewControllerWithIdentifier("second_vc") as! SecondViewController
    
    //Create third View
    let thirdVC = UIStoryboard(name: "Main", bundle: nil)
        .instantiateViewControllerWithIdentifier("third_vc") as! ThirdViewController
    
    //Create NavigationController and set both view to this one
    let navigationController = UINavigationController()

    navigationController.navigationBar.barStyle = .BlackTranslucent
    navigationController.setViewControllers([secondVC, thirdVC], animated: true)
    presentViewController(navigationController, animated: true, completion: nil)
}

Thanks to setViewControllers([secondVC, thirdVC], animated: true) method I can create such behavior for my controllers. It will open third view controller with animation and will add second view controller to the stack right before third one.

iphone6_plus_

Eventually, my attempts reached the expected result.