Marcel Gangwisch
Marcel Gangwisch

Reputation: 9026

WKWebview not fully loaded in iOS 10.3

I got the problem that I'm loading a local html file in a WKWebview. My procedure is working for iOS 8, 9, 11 but not for 10.3. There is just white space in the middle of the text.

I'm creating my WKWebview like this:

let webConfiguration = WKWebViewConfiguration();
let frame = CGRect(x: 0, y: 0, width: cell.frame.width, height: self.webViewHeight);
infoWebView = WKWebView(frame: frame, configuration: webConfiguration);
infoWebView.navigationDelegate = self;
infoWebView.translatesAutoresizingMaskIntoConstraints = false
infoWebView.scrollView.isScrollEnabled = false;
infoWebView.clipsToBounds = false;
infoWebView.allowsBackForwardNavigationGestures = false
infoWebView.contentMode = .scaleToFill
infoWebView.sizeToFit()

The loading of my html file is done by the following code:

if let availableUrl = url {
                let urlRequest = URLRequest(url: availableUrl)
                infoWebView.load(urlRequest)
            }

Do you have an idea why it's working for iOS 8,9,11 but not for iOS 10.3? Can somebody reproduce this problem?

Kind regards and have a nice day!

Upvotes: 1

Views: 978

Answers (1)

Marcel Gangwisch
Marcel Gangwisch

Reputation: 9026

Since I had my wkwebview in a table view I had to override scrollViewDidScroll from UITableViewDelegate.

this code from WKWebView not rendering correctly in iOS 10 did the trick for me:

// in the UITableViewDelegate
func scrollViewDidScroll(scrollView: UIScrollView) {
    if let tableView = scrollView as? UITableView {
        for cell in tableView.visibleCells {
            guard let cell = cell as? MyCustomCellClass else { continue }
            cell.webView?.setNeedsLayout()
        }
    }
}

Upvotes: 1

Related Questions