简体   繁体   English

使用导航控制器时,关闭视图控制器不起作用

[英]Dismissing View Controller Doesn't Work While Using Navigation Controller

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. 将segue设置为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. 一旦我转到第二个视图控制器,就会有一个Bar Button Item ,它是一个IBAction ,应该关闭该页面,但不是。

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. 在您的donePressed(_:)函数中,访问导航控制器并调用popViewController(_:)函数。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 关闭导航视图控制器 - Dismissing a navigation view controller 解除呈现的视图控制器将不起作用 - Dismissing presented view controller won't work 使用标签栏和导航控制器将视图转移到错误的视图 - View is dismissing to the wrong view with tabbar and navigation controller iPhone App - 关闭模态视图 controller 不会释放它 - iPhone App - dismissing modal view controller doesn't dealloc it 取消ZXingWidgetController后在Navigation Controller中显示视图 - Showing a view in Navigation Controller after dismissing ZXingWidgetController 在没有导航控制器的情况下关闭以前的视图控制器的同时转到新的视图控制器:swift - Segueing to New View Controller while Dismissing previous without navigation controller: swift 如何在不删除整个堆栈的情况下关闭导航控制器中的视图控制器 - How to dismiss a view controller in a navigation controller, without dismissing the whole stack 何时在解除视图控制器时自行解除分配 - When is self deallocated while dismissing view controller 导航控制器未显示视图 - navigation controller doesn't show up the view preferredStatusBarStyle .lightContent 不适用于导航控制器 - preferredStatusBarStyle .lightContent doesn't work with Navigation Controller
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM