をリロードします。 webviewがhtmlコンテンツのロードを完了すると、正しい高さでセルをリロードしようとしています。のUITableView reloadRowsAtIndexPathsは継続的に私はのUIWebViewを含むカスタムセルとのUITableViewを持っているセル
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
height = tableView.frame.size.height - tableView.contentSize.height
return height
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell:UITableViewCell!
cell = tableView.dequeueReusableCellWithIdentifier("bodyFieldCellIdentifier", forIndexPath: indexPath)
(cell as! SMBodyTableViewCell).frame = CGRect(x: 0, y: 0, width: width, height: height)
(cell as! SMBodyTableViewCell).bodyWebView.delegate = self
(cell as! SMBodyTableViewCell).bodyWebView.loadHTMLString(self.messageBody, baseURL: nil)
(cell as! SMBodyTableViewCell).bodyWebView.tag = indexPath.row
}
webViewDidFinishLoadデリゲートメソッドでは、webviewを含むセルをリロードしようとします。
func webViewDidFinishLoad(aWebView: UIWebView) {
let indexPath = NSIndexPath(forRow: aWebView.tag, inSection: 0)
self.tableView.reloadRowsAtIndexPaths([indexPath], withRowAnimation: .Automatic)
}
アプリを実行すると、webviewを含むセルが連続してリロードされます。高さは正しいと思われますが、ノンストップでリロードしているセルを確認できます。なぜ私はそれが継続的にリロードするのか分からないようです。私がロードしているHTMLコンテンツはシンプルなHTMLであり、複数の/無限のフレームを持たないので、webViewDidFinishLoadが連続的に呼び出されます。また、webViewDidLoadでセルの高さを再計算して設定しようとしましたが、高さが正しく計算されていないようです。