Disable multiple view controllers showing the wrong view during a transition

I have a total of 4 UIViewControllers. Each of the views has a button that, when clicked, represents the next view manager. When the button on the last UIViewController is pressed, the rejectViewControllerAnimated (true, completion: nil) function is called on the root controller. When called, it immediately renders View # 2, instead of staying with View # 4 when it transitions back to View # 1. The documentation says that when you do this, the topmost view is the only view that will be animated during dismissal, but is that not the case for me? This also happens if I used segues.

class ViewController1: UIViewController {
    @IBAction func btnDidTouch(sender: AnyObject) {
        var viewController = self.storyboard!.instantiateViewControllerWithIdentifier("ViewController2") as! UIViewController
        self.presentViewController(viewController, animated: true, completion: nil)
    }
}
class ViewController2: UIViewController {
    @IBAction func btnDidTouch(sender: AnyObject) {
        var viewController = self.storyboard!.instantiateViewControllerWithIdentifier("ViewController3") as! UIViewController
        self.presentViewController(viewController, animated: true, completion: nil)
    }
}
class ViewController3: UIViewController {
    @IBAction func btnDidTouch(sender: AnyObject) {
        var viewController = self.storyboard!.instantiateViewControllerWithIdentifier("ViewController4") as! UIViewController
        self.presentViewController(viewController, animated: true, completion: nil)
    }
}
class ViewController4: UIViewController {
    @IBAction func btnDidTouch(sender: AnyObject) {
        self.view.window?.rootViewController!.dismissViewControllerAnimated(true, completion: nil)
    }
}

      

+3


source to share





All Articles