Pull to refresh not working in iOS WebView

前端 未结 6 1923
野趣味
野趣味 2021-01-05 05:37

I\'ve implemented a straight forward WKWebView in iOS.

   var refreshControl = UIRefreshControl()
    refreshControl.addTarget(self, action: Sel         


        
6条回答
  •  囚心锁ツ
    2021-01-05 06:08

    SWIFT 4 Solution (Based on Nirav D answer)

    You can simply call this setup method in your viewDidLoad:

    private func setupRefreshControl() {
        let refreshControl = UIRefreshControl()
        refreshControl.addTarget(self, action: #selector(refreshWebView(sender:)), for: UIControlEvents.valueChanged)
        webView.scrollView.addSubview(refreshControl)
    }
    
    @objc
    private func refreshWebView(sender: UIRefreshControl) {
        print("refreshing...")
        webView.load(URLRequest(url: url))
        sender.endRefreshing()
    }
    

提交回复
热议问题