【发布时间】:2017-10-19 18:57:21
【问题描述】:
Video of web view reloading after shown on screen
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = UITableViewCell()
if indexPath.row == 17 {
let _cell = tableView.dequeueReusableCell(withIdentifier: "webCell") as! WebviewTableViewCell
let webView = UIWebView()
webView.frame = _cell.contentView.bounds
webView.scalesPageToFit = true
let webViewURL = "https://www.reddit.com/"
var _request = URLRequest(url: URL(string: webViewURL)!)
_request.cachePolicy = .returnCacheDataElseLoad
webView.loadRequest(_request)
_cell.contentView.addSubview(webView)
return _cell
}
cell.textLabel?.text = "sample cell \(indexPath.row + 1)"
return cell
}
我正在使用上面的代码来提供 Web 视图的缓存副本。但是,每次带有 Web 视图的单元格超出屏幕时,表格视图都会重新加载 Web 视图内容。如何在 web 视图中只加载一次页面,而不是每次单元格离开屏幕时加载它?任何帮助将不胜感激和投票。谢谢。
【问题讨论】:
标签: ios swift uitableview uiwebview