我在提交ViewControllerB
后试图解除ViewControllerA我目前提供ViewControllerB的代码是:
let viewControllerB = ViewControllerB()
self.present(viewControllerB, animated: true, completion: nil)
我想要发生的是当加载ViewControllerB以解除ViewControllerA
时我尝试使用委托,以便ViewControllerB可以通知ViewControllerA它应该被解雇,但会发生的事情是ViewControllerB被解雇了:
ViewControllerB中的Delegate和viewDidAppear()函数:
protocol DismissDelegate : class {
func dismissVC (_ dismiss: Bool)
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
delegate?.dismissVC(true)
}
和ViewControllerA中的回调
func dismissVC(_ dismiss: Bool) {
print("dismissVC delegate")
ViewControllerA().dismiss(animated: false, completion: nil)
}
如果这有任何不同,我不会在我的应用程序中使用故事板。
关于我做错了什么或根本不做什么的任何指示?
答案 0 :(得分:2)
您正在viewControllerB
展示viewControllerA
。如果viewControllerA
viewControllerB
正在呈现viewControllerA
的视图控制器,则您无法关闭viewControllerB
。
您必须先解除viewControllerA
,然后在完成区中再显示viewControllerB
,请尝试以下操作:
let customerMenu = CustomerMenuVC()
// this should dismiss current view controller
let presentingVC = self.presentingViewController!
self.dismiss(animated: false) {
presentingVC.present(customerMenu, animated: true, completion: nil)
}