1
votes

I have two view controllers.

The first one is embedded in a Navigation Controller. On the first view controller there is Bar Button Item which is connected by a segue to the second view controller. The segue is set as Push. Once I go to the second view controller there is a Bar Button Item which is an IBAction and should dismiss the page, but it doesn't.

Second View Controller Code:

import UIKit

class Page2ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

    }

    @IBAction func donePressed(_ sender: Any) {
        dismiss(animated: true, completion: nil)
    }

}
1
The opposite of "push" is "pop", not "dismiss".rmaddy
@rmaddy what is the function for "pop"user8969667
Look at the documentation for UINavigationController.rmaddy

1 Answers

3
votes

Within your donePressed(_:) function, access the navigation controller and call the popViewController(_:) function.

@IBAction func donePressed(_ sender: Any) {
     navigationController?.popViewController(animated: true)
}