简体   繁体   English

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

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

I'm using the following pod for my SideMenu functionality. 将以下Pod用于我的SideMenu功能。 Now, if I opened it from XYZ viewController and selected the row which again opens the XYZ viewController, the page is being pushed, but instead, I want the SideMenu to be dismissed, no to push already presented viewController. 现在,如果我从XYZ viewController中打开它,然后选择再次打开XYZ viewController的行,则页面将被推送,但是我想关闭SideMenu,而不要推送已经显示的viewController。

Here is the UI: 这是用户界面:

在此处输入图片说明

And here is my didSelectRow code, which is quite clear: 这是我的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
    }
}

So far I've tried to detect the topMost viewController , get the presentingViewController property, but had no success. 到目前为止,我已经尝试检测topMost viewController ,获取presentingViewController属性,但是没有成功。 Can anyone help me handle it in a proper way? 谁能帮助我以正确的方式处理它?

try adding var previousVC: UIViewController? 尝试添加var previousVC: UIViewController? to the sideMenu root view controller (lets call it SideMenuVC) 到sideMenu根视图控制器(将其称为SideMenuVC)

then on each view controller form where you will present the side menu from add 然后在每个视图控制器表单上,您将在其中显示添加的侧边菜单

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

then on the XYZViewController case write 然后在XYZViewController的情况下写

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 检测ViewController是否显示为FormSheet - Detect if ViewController presented as FormSheet 如何知道在应用启动时显示哪个ViewController - How to know which viewcontroller is presented on app start swift 4 中的 SideMenu 功能 - SideMenu Functionality in swift 4 如何在不带NavigationController的情况下在viewController中制作CAAnimation - How to make CAAnimation in viewController, which presented without navigationController 从以模态呈现的 ViewController 更改按钮的文本 - Change the text of the button from ViewController which presented modally 延迟UIAlertView的显示,直到显示其关联的viewController - Delay the presentation of UIAlertView until its associated viewController is displayed 快速地从Presented ViewController转到Previous ViewController时调用哪种方法 - Which method is called when we go from Presented ViewController to Previous ViewController in swift 解除在ViewController中以编程方式呈现的ViewController,它嵌套在NavigationController崩溃中,但不是每次都崩溃 - Dismiss ViewController which was programmatically presented in ViewController nested in NavigationController crashes, but not every time 从其他视图控制器推送到 ViewController,显示为弹出框 - 没有故事板 - PUSH to ViewController from other viewcontroller which is presented as popover - WITHOUT STORY BOARD 设置ViewController的约束 - Set Constraints for ViewController presented
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM