且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

当 Webview 在集合视图单元格内时,如何检测 UIWebView 何时开始加载?

更新时间:2023-02-06 15:08:08

你需要在你的单元格中实现 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")
    }
}

希望能帮到你