title: How to add buttons to wkWebView?
body: <p>Because we make <code>wkWebView</code> as the root view, the button I added on my layout doesn't appear on screen. Then I tried to add <code>wkWebView</code> as a subview of the root view, but the app crashes. Then I found about <code>UIBarButtonItem</code>, but it seems that you could only create 2 buttons. </p>
  
  <p>I need to add 5 buttons anywhere on the screen. Is there a workaround for this? I'm a newbie on ios development and I'm not that good at using the interface builder.</p>
  
  <p>After trying @Matic Oblak's code and placing it on <code>loadView()</code> where I do my <code>wkwebview</code> initialization, I'm getting an error saying "Warning: Attempt to present SomeViewController on WebViewController whose view is not in the window hierarchy!</p>
  
  <p>This is my current code.</p>
  
  <pre><code>override func loadView() {
  //        let contentController: WKUserContentController = WKUserContentController()
  //        let config: WKWebViewConfiguration = WKWebViewConfiguration()
  //
  //        contentController.add(self, name: "callbackHandler")
  //        config.userContentController = contentController
  //
  //        webView = WKWebView(
  //            frame: UIScreen.main.bounds,
  //            configuration: config
  //        )
  
         //webView.navigationDelegate = self
         //webView.translatesAutoresizingMaskIntoConstraints = false
         //webView.scrollView.isScrollEnabled = false
  
         //view = webView
  
         if let webViewContainer = webviewContainer {
  
             // Initialize:
             let contentController: WKUserContentController = WKUserContentController()
             let config: WKWebViewConfiguration = WKWebViewConfiguration()
  
             contentController.add(self, name: "callbackHandler")
             config.userContentController = contentController
  
             let webView = WKWebView(frame: webViewContainer.bounds, configuration: WKWebViewConfiguration()) // Create a new web view
             webView.translatesAutoresizingMaskIntoConstraints = false // This needs to be called due to manually adding constraints
  
             webView.navigationDelegate = self
             webView.translatesAutoresizingMaskIntoConstraints = false
             webView.scrollView.isScrollEnabled = false
  
             // Add as a subview:
             webViewContainer.addSubview(webView)
  
             // Add constraints to be the same as webViewContainer
             webViewContainer.addConstraint(NSLayoutConstraint(item: webView, attribute: .leading, relatedBy: .equal, toItem: webViewContainer, attribute: .leading, multiplier: 1.0, constant: 0.0))
             webViewContainer.addConstraint(NSLayoutConstraint(item: webView, attribute: .trailing, relatedBy: .equal, toItem: webViewContainer, attribute: .trailing, multiplier: 1.0, constant: 0.0))
             webViewContainer.addConstraint(NSLayoutConstraint(item: webView, attribute: .top, relatedBy: .equal, toItem: webViewContainer, attribute: .top, multiplier: 1.0, constant: 0.0))
             webViewContainer.addConstraint(NSLayoutConstraint(item: webView, attribute: .bottom, relatedBy: .equal, toItem: webViewContainer, attribute: .bottom, multiplier: 1.0, constant: 0.0))
  
             // Assign web view for reference
             self.webView = webView
         }
     }
  
  override func viewDidLoad() {
      if(someVar1.isEmpty &amp;&amp; someVar2.isEmpty){
             showSomeDialog()
         }
  }
  </code></pre>
  
  <p>The first commented lines on <code>loadView()</code> are my previous code for reference.</p>
  
  <p>After placing @Matic Oblak's code on <code>viewDidLoad()</code>, I'm getting a black screen. Also, after placing the code that calls <code>SomeViewController</code> on <code>viewDidAppear()</code>, the error is gone but I'm still getting the black screen.</p>