Search code examples
swiftswift2pushios9modalviewcontroller

swift dismiss modal and push to new VC


I have tableview... 1 table showing a new modal window and when I press the button I want to dismiss the modal window and push to VC. My code only hide the modal view but no push is made.

    @IBAction func registrationBtn(sender: AnyObject) {

    let openNewVC = self.storyboard?.instantiateViewControllerWithIdentifier("registrationVcID") as! RegistrationVC

    self.dismissViewControllerAnimated(false, completion: { () -> Void   in
         self.navigationController?.pushViewController(openNewVC, animated: true)

            })
}

Solution

  • You should create a protocol

    protocol View1Delegate: class {
        func dismissViewController(controller: UIViewController)
    }
    

    When you tap button on Register will call delegate back to TableView. TableViewController should implement:

      func dismissViewController(controller: UIViewController) {
        controller.dismissViewControllerAnimated(true) { () -> Void in
            //Perform segue or push some view with your code
    
        }
    }
    

    You can do anything in here. Push screen you want. Detail implement you can see my demo: Demo Push View in Swift