Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UICollectionView内部的WebView动态内容大小_Ios_Swift_Uicollectionview_Wkwebview - Fatal编程技术网

Ios UICollectionView内部的WebView动态内容大小

Ios UICollectionView内部的WebView动态内容大小,ios,swift,uicollectionview,wkwebview,Ios,Swift,Uicollectionview,Wkwebview,我试图通过引用collectionViewCell来调整UICollectionViewCell中的WKWebView动态HTML内容的大小。工作正常,但有时在下一行展开可选值时抛出意外发现的nil: let cell:CollectionViewCell = collectionView!.cellForItem(at: indexpath) as! CollectionViewCell 这是我的密码: func webView(_ webView: WKWebView, didFinish

我试图通过引用
collectionViewCell
来调整UICollectionViewCell中的WKWebView动态HTML内容的大小。工作正常,但有时在下一行展开可选值时抛出意外发现的nil:

let cell:CollectionViewCell = collectionView!.cellForItem(at: indexpath) as! CollectionViewCell
这是我的密码:

func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!)
{
        let indexpath: IndexPath = IndexPath.init(item: self.pageControl.currentPage, section: 0)
        let cell:CollectionViewCell = collectionView!.cellForItem(at: indexpath) as! CollectionViewCell
        cell.newsWebView?.evaluateJavaScript("document.readyState", completionHandler: { (result, error) in
            if result == nil || error != nil {
                return
            }
            cell.newsWebView?.evaluateJavaScript("document.body.offsetHeight", completionHandler: { (result, error) in
                if let height = result as? CGFloat {
                    cell.webviewHeightConstraint?.constant = height
                }
            })
    CustomeLoader.instance.hideLoader()
}
致命错误:在展开可选值时意外发现nil


试试这个。此崩溃可能是由于渲染延迟造成的

let when = DispatchTime.now() + 1
DispatchQueue.main.asyncAfter(deadline: when) {
       let indexpath: IndexPath = IndexPath.init(item: pageControl.currentPage, section: 0)
        let cell:CollectionViewCell = collectionView!.cellForItem(at: indexpath) as! CollectionViewCell
         cell.newsWebView.evaluateJavaScript("document.readyState", completionHandler: { (complete, error) in
            if complete != nil {
                cell.newsWebView.evaluateJavaScript("document.body.offsetHeight", completionHandler: { (height, error) in
                    cell.webviewHeightConstraint.constant = height as! CGFloat
                })
            }

        })         
}

试试这个。此崩溃可能是由于渲染延迟造成的

let when = DispatchTime.now() + 1
DispatchQueue.main.asyncAfter(deadline: when) {
       let indexpath: IndexPath = IndexPath.init(item: pageControl.currentPage, section: 0)
        let cell:CollectionViewCell = collectionView!.cellForItem(at: indexpath) as! CollectionViewCell
         cell.newsWebView.evaluateJavaScript("document.readyState", completionHandler: { (complete, error) in
            if complete != nil {
                cell.newsWebView.evaluateJavaScript("document.body.offsetHeight", completionHandler: { (height, error) in
                    cell.webviewHeightConstraint.constant = height as! CGFloat
                })
            }

        })         
}

在以下let单元格中展开可选值时,意外发现同一问题为nil:CollectionViewCell=collectionView!。cellForItem(位于:indexpath)为!CollectionViewCell。在cellforItem中写入动态内容代码后,未崩溃,但未调用动态内容大小。在下面的let cell:CollectionViewCell=collectionView!中展开可选值时,意外发现相同问题为零!。cellForItem(位于:indexpath)为!CollectionViewCell。在cellforItem中写入动态内容代码后,未崩溃,但未调用动态内容大小。