Inside my Custom TabBarController I set the NavigationController for each tab
let viewController = [HomeViewController(), ProfileViewController()]
let navControllers = viewControllers.map { return UINavigationController(rootViewController: $0) }
setViewControllers(navControllers, animated: false)
In my HomeViewController I have a CollectionView that when selecting a cell it pushes my VideoPlayerViewController to the NavigationController. The VideoPlayerViewController then presents a ViewController as a modal:
class PopoverViewController: UIViewController {
@IBAction func presentPopover() {
let popoverViewController = PopoverViewController()
popoverViewController.modalPresentationStyle = .fullScreen
popoverViewController.delegate = self
present(popoverViewController, animated: true, completion: nil)
}
}
In my PopoverViewController I have a close button that calls the delegate method in the VideoPlayerViewController:
class PopoverViewController: UIViewController {
@objc func closeTapped() {
delegate?.willClose(self)
}
}
extension VideoPlayerViewController: PopoverViewControllerDelegate {
func willClose(_ viewController: PopoverViewController) {
viewController.dismiss(animated: true, completion: nil)
}
}
When calling dismiss on my PopoverViewController it not only dismisses the modal ViewController but it also pops the VideoPlayerViewController from the NavigationController and it returns to the rootViewController (HomeViewController).
I want to go back to the VideoPlayerViewController and only dismiss the PopoverViewController without popping the VideoPlayerViewController.
You are calling the dismiss on your VideoPlayerViewController. This should be done on the PopoverViewController as below:
class PopoverViewController: UIViewController {
@objc func closeTapped() {
dismiss(animated: true, completion: nil)
}
}
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