I guess because performUpdatesAnimated is not finished.
sorry for poor english!
README and documentationIGListKit version:2.2.1Hey @FengDeng! Could you provide a stack trace or example project reproducing this issue? We're going to need a little bit more information to look into this.
sample description:
I have a webview in one sectionController. And need reload height after webview load finished.
Adapter called performUpdatesAnimated(true),if webview load finished soon and reload it's sectioncontroller,it's invaild.webview sectionController height not changed.It's not 100 percent.sometime reload success and height changed.
i guess the sectionController reloading when adapter animationing?
in webview sectionController
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
webView.evaluateJavaScript("document.body.offsetHeight") { (height, err) in
guard let height = height as? NSNumber else{return}
self.height = CGFloat(height.floatValue) + 15
self.data?._height = self.height
print(self.height)
self.data?.reloadData()
print("reloadData begin")
/*
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 1.0, execute: {
self.data?.reloadData()
print("鍥犱负html锛歕(self.data?.sectionViewController?.viewController)")
})*/
}
}
func reloadData(){
self.sectionViewController?.collectionContext?.reload(self.sectionViewController!)
}
if delay 1.0 second,and webview sectionController height changed!
@FengDeng oh nice, I think @ocrickard had some similar experiences too when he was doing some prototyping.
Instead of just reloading, could you try wrapping it in a batch update and see if that works?
Something like:
collectionContext?.performBatch(animated: true, updates: {
self.collectionContext?.reload(self)
})
That should work, we use this workaround as well.
@jessesquires @rnystrom Thanks,it works!
Hi @FengDeng can you elaborate more about your solution I'm trying to implement something similar but the app crashes.
libc++abi.dylib: terminating with uncaught exception of type NSException
Removing the WKWebView delegate from the sell solves the crash but I'm not sure why.
Are you using self-sizing cells?
initializing the webview
lazy public var webView: WKWebView = {
let webView: WKWebView = WKWebView(frame: .zero)
webView.translatesAutoresizingMaskIntoConstraints = false
webView.scrollView.isScrollEnabled = false;
webView.allowsBackForwardNavigationGestures = false
return webView
}()
///....
func bindViewModel(_ viewModel: Any) {
guard let vm = viewModel as? WebViewContentModel else { return }
let urlPath = URL(fileURLWithPath: Bundle.main.bundlePath)
webView.navigationDelegate = self
webView.stopLoading()
webView.loadHTMLString(vm.htmlTemplate, baseURL: urlPath)
}
Most helpful comment
@jessesquires @rnystrom Thanks,it works!