WebView in Table Cell - Automatic height - Swift

Viewed 54

WebView in Table Cell - Automatic height - Swift.

I want the height of WebView and Table Cell to be automatically adjusted.

The table is static.

var contentHeights : CGFloat = 0


func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {

self.webView.evaluateJavaScript("document.readyState", completionHandler: { (complete, error) in
    if complete != nil {
         self.webView.evaluateJavaScript("document.body.scrollHeight", completionHandler: { (height, error) in
              self.contentHeights = height as! CGFloat
              self.tableView.beginUpdates()
              self.tableView.endUpdates()
         })
     }

   })

}

override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
   if indexPath.row == 0 {
       return 300
   }
   return contentHeights
}
0 Answers
Related