使用导航控制器时,关闭视图控制器不起作用 [英] Dismissing View Controller Doesn't Work While Using Navigation Controller

查看:44
本文介绍了使用导航控制器时,关闭视图控制器不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个视图控制器.

第一个嵌入在导航控制器中.在第一个视图控制器上有 Bar Button Item,它通过 segue 连接到第二个视图控制器.转场设置为推送.一旦我转到第二个视图控制器,就会有一个 Bar Button Item,它是一个 IBAction 应该关闭页面,但它没有.>

第二个视图控制器代码:

导入 UIKit类 Page2ViewController: UIViewController {覆盖 func viewDidLoad() {super.viewDidLoad()}@IBAction func donePressed(_ sender: Any) {解雇(动画:真实,完成:无)}}

解决方案

在你的 donePressed(_:) 函数中,访问导航控制器并调用 popViewController(_:)代码>函数.

@IBAction func donePressed(_ sender: Any) {导航控制器? .popViewController(动画:真)}

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)
    }

}

解决方案

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

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

这篇关于使用导航控制器时,关闭视图控制器不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆