0

I'm using the following pod for my SideMenu functionality. 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.

Here is the UI:

enter image description here

And here is my didSelectRow code, which is quite clear:

    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. Can anyone help me handle it in a proper way?

Emma V.
  • 99
  • 1
  • 8

1 Answers1

0

try adding var previousVC: UIViewController? to the sideMenu root view controller (lets call it 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

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