关闭推送的视图控制器
Dismiss pushed view controller
所以我有一个显示如下的视图控制器:
func showProfileForTrainer(trainer: Trainers) {
let viewPTProfileVC = ViewPTProfileVC()
viewPTProfileVC.trainer = trainer
self.navigationController?.pushViewController(viewPTProfileVC, animated: true)
}
但是当我试图关闭视图时,我无法让它工作。它在导航栏中有一个后退按钮,功能正常,但是当试图通过按钮关闭视图时,它什么都不做。我目前尝试过:
func handleMessageTrainer() {
dismiss(animated: true) {
print(1)
self.tabBarVC?.showChatLogForTrainer(trainer: self.trainer!)
}
self.dismiss(animated: true) {
print(2)
self.tabBarVC?.showChatLogForTrainer(trainer: self.trainer!)
}
navigationController?.dismiss(animated: true, completion: {
print(3)
self.tabBarVC?.showChatLogForTrainer(trainer: self.trainer!)
})
self.navigationController?.dismiss(animated: true, completion: {
print(4)
self.tabBarVC?.showChatLogForTrainer(trainer: self.trainer!)
})
print(5)
}
如您所见,我已经尝试了多种方法并且 none 有效,控制台只输出 5
。
令人沮丧的是,在我的应用程序的其他地方,我以与开头所示相同的方式呈现了一个视图,并且使用 dismiss(animated: true) { ... }
很好地取消了
知道为什么它在这里不起作用吗?
如果您使用 pushviewcontroller method
那么要 dismiss
您必须使用 popviewcontroller method
.
试试这个:
self.navigationController?.popViewController(animated: true)
您必须弹出来自相应导航控制器的视图控制器:
self.navigationController?.popViewController(animated: true)
所以我有一个显示如下的视图控制器:
func showProfileForTrainer(trainer: Trainers) {
let viewPTProfileVC = ViewPTProfileVC()
viewPTProfileVC.trainer = trainer
self.navigationController?.pushViewController(viewPTProfileVC, animated: true)
}
但是当我试图关闭视图时,我无法让它工作。它在导航栏中有一个后退按钮,功能正常,但是当试图通过按钮关闭视图时,它什么都不做。我目前尝试过:
func handleMessageTrainer() {
dismiss(animated: true) {
print(1)
self.tabBarVC?.showChatLogForTrainer(trainer: self.trainer!)
}
self.dismiss(animated: true) {
print(2)
self.tabBarVC?.showChatLogForTrainer(trainer: self.trainer!)
}
navigationController?.dismiss(animated: true, completion: {
print(3)
self.tabBarVC?.showChatLogForTrainer(trainer: self.trainer!)
})
self.navigationController?.dismiss(animated: true, completion: {
print(4)
self.tabBarVC?.showChatLogForTrainer(trainer: self.trainer!)
})
print(5)
}
如您所见,我已经尝试了多种方法并且 none 有效,控制台只输出 5
。
令人沮丧的是,在我的应用程序的其他地方,我以与开头所示相同的方式呈现了一个视图,并且使用 dismiss(animated: true) { ... }
知道为什么它在这里不起作用吗?
如果您使用 pushviewcontroller method
那么要 dismiss
您必须使用 popviewcontroller method
.
试试这个:
self.navigationController?.popViewController(animated: true)
您必须弹出来自相应导航控制器的视图控制器:
self.navigationController?.popViewController(animated: true)