title: Swift : call view controller in func webView(webView: UIWebView, shouldStartLoadWithRequest
body: <p>I want to call another viewcontroller in  <code>func webView(webView: UIWebView, shouldStartLoadWithRequest request: NSURLRequest, navigationType: UIWebViewNavigationType)</code> but there is error </p>
  
  <blockquote>
    <p>Error : UIWebViewExample[18859:1229622] Warning: Attempt to present  on  whose view is not in the window hierarchy!</p>
  </blockquote>
  
  <p>I googled and know that I should call view controller in '<strong>ViewDidLoad</strong>'. however I want to pop up view controller of login directly when I touch '<strong>login</strong>' button in <code>webview</code>.</p>
  
  <p>Here is my code</p>
  
  <pre><code>func webView(webView: UIWebView, shouldStartLoadWithRequest request: NSURLRequest, navigationType: UIWebViewNavigationType) -&gt; Bool {
  
      let surl = request.URL?.absoluteString
  
      if  surl ==  "http://myurl/m/include/login.php"{
          print("login pressed")
  
  
          ////call login view controller
         var dvc = ViewController()
         dvc.openNewViewController()
  
         return false
  
      }
  
      return true
  }
  
  public func openNewViewController(){
      var newController = LoginViewController() 
      self.presentViewController(newController, animated: true, completion: nil)
  }
  </code></pre>