WKWebView not rendering after first loadRequest

Hello,

I am having an issue with WKWebView. The very first call to the loadRequest method with default url works like a charm. However all subsequent loadRequest calls that arise from choosing a course from the list don’t cause the WKWebView to update. I debugged through the code and verified that the new selection triggered the delegate callback in the MainSplitViewController to be called. I also verified that the URL of the selected item was passed into detailViewController.loadURL method. The interesting thing is that I implemented the WKNavigationDelegate on the WebViewController class and verified that the didCommitNavigation and didFinishNavigation methods are called and that none of the error methods are invoked. It’s just that the content of the WKWebView isn’t updated. I am doing this under Swift 2.0 with Xcode 7 Beta 6. Any ideas are appreciated.

Regards,
Rob

I have found the issue and believe I have a fix for it. Turns out the viewDidLoad() method of the WebViewController is being called twice. It is the reason I see the default web page load with the first load request and then all subsequent loads appear not to work. The first time through viewDidLoad() creates the WKWebView and assigns it to the view member variable replacing the NSView instance that was created by default from the storyboard. This assignment to the view member is what I believe triggers another call to viewDidLoad to be scheduled as the WKWebView will now be loaded. However before the next call to viewDidLoad() executes the MainSplitViewController (in its viewDidLoad) will call loadRequest with the defaultURL on the detailViewController. This is what I see load. Now when the next viewDidLoad() executes on the WebViewController it will create another a WKWebView and assign to the view member variable overwriting the original WKWebView. This second WKWebView is not visible but it is the WKWebView that all subsequent loadRequests will end up being sent to since it is now referenced by the view variable. In order to correct this I modified the viewDidLoad method of the WebViewController to check to see if the view variable already references a WKWebView. If it does than the creation of a new WKWebView is skipped. It looks as follows:

override func viewDidLoad() {
        super.viewDidLoad()
        if !(view is WKWebView) {
            let webView = WKWebView()
            webView.navigationDelegate = self
            view = webView
        }
}