So I have a view controller which I display as follows:
func showProfileForTrainer(trainer: Trainers) {
let viewPTProfileVC = ViewPTProfileVC()
viewPTProfileVC.trainer = trainer
self.navigationController?.pushViewController(viewPTProfileVC, animated: true)
}
But when trying to dismiss the view, I cannot get it to work. It has a back button in a navigation bar which functions fine, but when trying to dismiss the view via a button for example, it does nothing. I have currently tried:
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)
}
As you can see I have tried varying ways and none work, and the console just outputs 5
.
Frustratingly, elsewhere in my app I presented a view in the same way as shown at the beginning and it dismissed fine using dismiss(animated: true) { ... }
Any idea why it won't work here?
You must pop the view controller from the corresponding navigation controller:
self.navigationController?.popViewController(animated: true)
If you are using pushviewcontroller method
then to dismiss
you have to use popviewcontroller method
.
Try this:
self.navigationController?.popViewController(animated: true)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With