title: Swift - Open UIViewController from within slide-in menu
body: <p>I have a slide-in menu that presents itself when I press the menu button in my navigation bar. Dismissing it can be accomplished by either tapping the background or the menu itself. Within this view I have several items, one of which is an user profile button. When I press this button, I want the menu to dismiss itself and then instantly open the user profile view controller. That's why I call <strong>handleDismiss()</strong> first and then set the view that needs to be opened</p>
  
  <p>However, it keeps telling me that the view is not in the window hierarchy. I know what the problem is (view stack), but I somehow can't get it to work properly. How should I tackle this problem?</p>
  
  <p><em>RootViewController -> HomeController (tabBar index 0) -> Slide-In Menu -> UserProfileController</em></p>
  
  <p><strong>Button to open the controller</strong></p>
  
  <pre><code>profileCell.profileButton.addTarget(self, action: #selector(handleUserProfile(sender:)), for: .touchUpInside)
  </code></pre>
  
  <p><strong>Functions</strong></p>
  
  <pre><code>func handleDismiss() {
      UIView.animate(withDuration: 0.5) {
          self.blackView.alpha = 0
  
          if let window = UIApplication.shared.keyWindow {
              self.collectionView.frame = CGRect(x: 0, y: window.frame.height, width: self.collectionView.frame.width, height: self.collectionView.frame.height)
          }
      }
  }
  
  func handleUserProfile(sender: UIButton) {
      handleDismiss()
  
      let userProfileController = UserProfileController()
      openProfileController(userProfileController)
  }
  
  func openProfileController(_ controller: UIViewController) {
     present(controller, animated: false, completion: nil)
  }
  </code></pre>