Я реализую wkwebviews в моем табличном представлении, где я вычисляю высоту табличного представления, сохраняю его в массиве и перезагружаю определенную ячейку. Но мой heightForRowAt indexPath вызывает сбой.
var contentHeights : [CGFloat] = [400.0, 0.0, 0.0, 0.0,0.0]
У меня есть 5 ячеек, высота первой ячейки определена, остальные все 4 состоит из wkwebview.
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(100)) {
if webView.tag < self.contentHeights.count{
let currentContentHeight = webView.scrollView.contentSize.height
if (self.contentHeights[webView.tag] < 50.0 && self.contentHeights[webView.tag] < currentContentHeight) {
self.contentHeights[webView.tag] = webView.scrollView.contentSize.height
webView.frame = CGRect(x: webView.frame.origin.x, y: webView.frame.origin.y, width: webView.frame.width, height: currentContentHeight)
self.uiViewController?.reloadTableViewrow(atIndexPath: webView.tag)
}
}
}
}
func reloadTableViewrow(atIndexPath:Int){
jobDetailTableview.reloadRows(at: [IndexPath(row: atIndexPath, section: 0)], with: .none)
}
Я назначаю тег webviewв cellForRowAt indexPath
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if indexPath.row == 0 {
let cell = tableView.dequeueReusableCell(withIdentifier: “X1”, for: indexPath) as? X1
if cell == nil {
LogError.logErrorRequest(message: "nil jobInfo cell for index = \(indexPath.row) for title = \(jobWebviewDetails[indexPath.row].name)", functionName: #function, className: "JobDetailDelegateAndDataSource", lineNumber: "\(#line)")
}
return cell!
} else {
let cell = tableView.dequeueReusableCell(withIdentifier: X2, for: indexPath) as? X2
cell?.selectionStyle = .none
cell?.webview.tag = indexPath.row
if cell == nil {
LogError.logErrorRequest(message: "nil jobDetails cell for index = \(indexPath.row) for title = \(jobWebviewDetails[indexPath.row].name)", functionName: #function, className: "JobDetailDelegateAndDataSource", lineNumber: "\(#line)")
}
return cell!
}
}
Но я получаю журналы сбоев в функциях HeightForRowAtIndexPath. Я пытался помещать журналы, но все еще безуспешно
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
if indexPath.row == 0 {
return 340.0
} else {
if indexPath.row < contentHeights.count {
return (contentHeights[indexPath.row] + 70)
} else {
// I am getting this logs, Its running fine on 90% on devices but getting this logs for few devices
LogError.logErrorRequest(message: "Index path = \(indexPath.row) ", functionName: #function, className: "x1", lineNumber: "\(#line)")
return 200
}
}
}
Я думаю, что потому что я устанавливаю и получаю массив вв то же время может быть причиной этой проблемы. Как решить эту проблему