我将the following pod用于我的SideMenu功能。现在,如果我从XYZ viewController中打开它,然后选择再次打开XYZ viewController的行,则页面将被推送,但是,我希望关闭SideMenu,而不必推送已经显示的viewController。

这是用户界面:

ios - 检测哪个 View  Controller 显示了侧边菜单,并为其显示实现了适当的功能-LMLPHP

这是我的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)

然后在每个视图控制器表单上,您将在其中显示添加的侧边菜单

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
}

10-04 21:04