This question already has answers here:
How to dismiss ViewController in Swift?
(20个答案)
3年前关闭。
我在解雇VC时有一点问题。
我的项目有2个Viewcontroller。 Viewcontroller A和ViewcontrollerB。
Viewcontroller A有一个按钮。如果我按此按钮,第二个ViewController B弹出。
第二个ViewController(B)有一个按钮。
如果我单击此按钮,此操作将开始:
此操作实际上应该关闭Viewcontroller,并应再次向我显示ViewcontrollerA。
但是,如果按此按钮,则什么也不会发生。
我忘了什么吗?
(20个答案)
3年前关闭。
我在解雇VC时有一点问题。
我的项目有2个Viewcontroller。 Viewcontroller A和ViewcontrollerB。
Viewcontroller A有一个按钮。如果我按此按钮,第二个ViewController B弹出。
第二个ViewController(B)有一个按钮。
如果我单击此按钮,此操作将开始:
@IBAction func dismiss(_ sender: UIBarButtonItem) {
self.presentedViewController?.dismiss(animated: true, completion: nil)
}
此操作实际上应该关闭Viewcontroller,并应再次向我显示ViewcontrollerA。
但是,如果按此按钮,则什么也不会发生。
我忘了什么吗?
最佳答案
应该:
@IBAction func dismiss(_ sender: UIBarButtonItem) {
self.dismiss(animated: true, completion: nil)
}
presentedViewController
的Viewcontroller B
为nil,这就是为什么什么也没有发生的原因。 presentedViewController
的Viewcontroller A
是您的Viewcontroller B