Stack
Stack

Reputation: 31

how to dismiss current view controller while segue time in swift3

This is my segue method. Let's say this method is in ParentViewController.

override fu n c prepare(for segue: UIStoryboardSegue, sender: Any?) {

    if segue.identifier == "subViewController" {
        // Before appears in the screen.
        let subViewController = segue.destination as! SubViewController
        subViewController.currentMarks = sender as? Int16
}

It is working perfect. Now coming to SubViewController. Here I'm doing some thing and I have a button here. Whenever I click this button it should dismiss SubViewController and needs to open ParentViewController (not opening because it's already opened state only).

Exactly whenever I click button in SubViewController, subViewController just needs to dismiss then automatically ParentViewController will be visible I think (because already opened one only I'm not closed right?).

How to implement like this mechanism? In SubViewController button action I have written this:

self.navigationController?.dismiss(animated: true, completion: {
    })

but it didn't work. Can anybody help me please?

Upvotes: 2

Views: 3690

Answers (1)

dilaver
dilaver

Reputation: 684

If you chose show when you created your segue on stoyboard. Call this in your button click:

self.navigationController?.popViewController(animated: true)

If you chose present modally call this:

self.dismiss(animated: true, completion: nil)

Upvotes: 9

Related Questions