VideoPlayerViewController

VideoPlayerViewController

在我的自定义TabBarController中,我为每个选项卡设置了NavigationController

let viewController = [HomeViewController(), ProfileViewController()]
let navControllers = viewControllers.map { return UINavigationController(rootViewController: $0) }
setViewControllers(navControllers, animated: false)

在我的HomeViewController中,我有一个CollectionView,它在选择一个单元格时会将我的VideoPlayerViewController推送到NavigationController。然后VideoPlayerViewController将ViewController呈现为模态:
class PopoverViewController: UIViewController {
    @IBAction func presentPopover() {
        let popoverViewController = PopoverViewController()
        popoverViewController.modalPresentationStyle = .fullScreen
        popoverViewController.delegate = self
        present(popoverViewController, animated: true, completion: nil)
    }
}

在我的PopoverViewController中,我有一个关闭按钮,该按钮在VideoPlayerViewController中调用委托方法:
class PopoverViewController: UIViewController {
    @objc func closeTapped() {
        delegate?.willClose(self)
    }
}

extension VideoPlayerViewController: PopoverViewControllerDelegate {
    func willClose(_ viewController: PopoverViewController) {
        viewController.dismiss(animated: true, completion: nil)
    }
}

当在我的PopoverViewController上调用dismiss时,它不仅关闭模态ViewController,而且还从NavigationController弹出VideoPlayerViewController,并返回到rootViewController(HomeViewController)。

我想回到VideoPlayerViewController并只关闭PopoverViewController而不弹出VideoPlayerViewController。

最佳答案

您正在VideoPlayerViewController上调用解雇程序。这应该在PopoverViewController上完成,如下所示:

class PopoverViewController: UIViewController {
    @objc func closeTapped() {
        dismiss(animated: true, completion: nil)
    }
}

关于ios - 如何正确消除模态视图 Controller ?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/58068122/

10-12 05:32