当 Webview 在集合视图单元格内时,如何检测 UIWebView 何时开始加载? [英] How to detect when UIWebView starts loading when Webview is inside a Collection View cell?
问题描述
我正在加载包含 UIWebView
的单元格集合视图.我的 UICollectionView
的活动指示器停止旋转和 UIWebView
加载之间存在时间间隔.我正在尝试获取加载开始时间(以及最终停止时间)的引用,以便添加另一个活动指示器 UI.我不知道如何在这里做,因为我的 UIWebView
在我的 CollectionViewCell
而不是我的 CollectionView
,换句话说我可以't 使用委托方法并在我的 collectionView
的 VDL 中将自己设置为我的委托?我的 CollectionViewCell
代码:
I am loading a collection view of cells containing UIWebView
s. There's a time gap between when my UICollectionView
's activity indicator stops spinning and the UIWebView
loads. I am trying to get a reference to when the loading starts (and eventually when it stops) in order to add another activity indicator UI. I'm not sure how to do it here though since my UIWebView
is in my CollectionViewCell
and not my CollectionView
, in other words I can't use the delegate methods and set myself as my delegate in my collectionView
s VDL? My CollectionViewCell
code:
import UIKit
import WebKit
class SearchCollectionViewCell: UICollectionViewCell {
@IBOutlet weak var webView: UIWebView!
@IBOutlet weak var spinner: UIActivityIndicatorView!
func webViewDidStartLoad(_ webView: UIWebView) {
print("we're loading")
}
}
推荐答案
你需要在你的单元格中实现 UIWebViewDelegate
并将你的单元格设置为 delegate
然后在方法 webViewDidStartLoad
你会收到通知
You need to implement UIWebViewDelegate
in your cell and set you cell as delegate
then in the method webViewDidStartLoad
you will be notified
import UIKit
import WebKit
class SearchCollectionViewCell: UICollectionViewCell {
@IBOutlet weak var webView: UIWebView!
@IBOutlet weak var spinner: UIActivityIndicatorView!
override func awakeFromNib() {
super.awakeFromNib()
self.webView.delegate = self
// Initialization code
}
}
extension SearchCollectionViewCell : UIWebViewDelegate
{
public func webViewDidStartLoad(_ webView: UIWebView) {
debugPrint("Start Loading")
}
}
希望能帮到你
这篇关于当 Webview 在集合视图单元格内时,如何检测 UIWebView 何时开始加载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!