检测哪个 viewController 显示了 SideMenu 并为其显示实现适当的功能

Detect which viewController presented the SideMenu and implement proper functionality for its presentation

我正在使用 the following pod 来实现我的侧边菜单功能。现在,如果我从 XYZ viewController 打开它并选择再次打开 XYZ viewController 的行,页面将被推送,但相反,我希望 SideMenu 被关闭,不推送已经呈现viewController.

这是UI:

这是我的 didSelectRow 代码,非常清楚:

    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    switch indexPath.row {
    case 0:
        let playerVC = NavigationHelper.shared.getStoryBoard().instantiateViewController(withIdentifier: "mainPage") as? MainViewController
        navigationController?.pushViewController(playerVC!, animated: true)
    case 1:
        let historyVC = NavigationHelper.shared.getStoryBoard().instantiateViewController(withIdentifier: "historyPage") as? BroadcastsHistoryViewController
        navigationController?.pushViewController(historyVC!, animated: true)
    case 2:
        let sendMessageVC = NavigationHelper.shared.getStoryBoard().instantiateViewController(withIdentifier: "messagingPage") as? MessaginViewController
        navigationController?.pushViewController(sendMessageVC!, animated: true)
    case 3:
        let settingsVC = NavigationHelper.shared.getStoryBoard().instantiateViewController(withIdentifier: "settingPage") as? SettingsViewController
        navigationController?.pushViewController(settingsVC!, animated: true)
    case 4:
        let aboutVC = NavigationHelper.shared.getStoryBoard().instantiateViewController(withIdentifier: "aboutPage") as? AboutAppViewController
        navigationController?.pushViewController(aboutVC!, animated: true)
    default: break
    }
}

到目前为止,我已经尝试检测 topMost viewController,获取 presentingViewController 属性,但没有成功。谁能帮我妥善处理一下?

尝试将 var previousVC: UIViewController? 添加到 sideMenu 根视图控制器(我们称之为 SideMenuVC)

然后在每个视图控制器表单上,您将在其中显示来自 add

的侧边菜单
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if let nextVC = segue.destination as? SideMenuVC {
        nextVC.previousVC = self
    }
}

然后在 XYZViewController 案例上写

if let vc = previousVC as? XYZViewController{
    //dismiss sidemenu
} else {
   //instantiate and push ViewController 
}