问题
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:
Within your donePressed(_:)
function, access the navigation controller and call the popViewController(_:)
function.
@IBAction func donePressed(_ sender: Any) {
navigationController?.popViewController(animated: true)
}
来源:https://stackoverflow.com/questions/51255265/dismissing-view-controller-doesnt-work-while-using-navigation-controller