Dismissing View Controller Doesn't Work While Using Navigation Controller

偶尔善良 提交于 2019-12-11 23:23:30

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!