【发布时间】:2018-01-01 00:20:12
【问题描述】:
我从UITabBarController (VC1) 开始
然后我在它上面显示一个UIViewController(VC2) 并将其名为parentController 的变量设置为self:
let loginController = LoginController()
DispatchQueue.main.async {
self.present(loginController, animated: false, completion: {
// Once presented, set parentController = self
loginController.parentController = self
})
}
然后,当用户点击“使用电子邮件登录按钮”时,我会继续在 VC2 之上显示第三个 UIViewController(VC3):
let withEmailController = WithEmailLoginController()
withEmailController.parentController = self
present(withEmailController, animated: true, completion: nil)
使用电子邮件注册后,我会展示第四张UIViewController(VC4),以便用户选择他们的个人资料图片
let profilePicturePickerController = ProfilePicturePickerController()
profilePicturePickerController.parentController = self
present(profilePicturePickerController, animated: true, completion: nil)
在用户选择了他们的头像后,我在 VC4 中调用此代码以尝试从 VC2 中的函数中消除 VC2、VC3 和 VC4:
parentController?.parentController?.handleDismiss()
VC2 中的handleDismiss 很简单:
func handleDismiss() {
// Progress MainTabBarController
parentController?.progressWithLoggedInUser()
// Dismiss the LoginController
self.dismiss(animated: true) {
// I do some things in here that aren't relevant to the question
}
}
问题:
当从 VC2 调用属于 VC2 的名为 handleDismiss 的函数时,一切正常,并且 VC2 被解除(VC3 和 VC4 没有被解除,因为它们还没有出现)。但是,当handleDismiss 像上面那样从 VC4 调用时,只有 VC3 和 VC4 被解除。 VC2 仍然存在。据我了解,VC1、2、3、4 都在同一个堆栈中。
我尝试过的:
将所有存在/关闭命令放入DispatchQueue.main.async {code}。
在 VC4 中直接调用parentController?.parentController?.dismiss(animated: true, completion: nil) 有同样的错误。从 VC2 调用 handleDismiss() 以确保它正常工作
我还看过的其他地方:
Dismiss more than one view controller simultaneously,Dismissing a Presented View Controller。我感觉设置那些parentController变量和使用presentingViewController是一样的
【问题讨论】:
标签: ios swift3 uiviewcontroller