Pull to refresh not working in iOS WebView

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

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

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


        
6条回答
  •  萌比男神i
    2021-01-05 06:03

    Try to change your code like this, If you want to pull to refresh the webView you need to addSubView UIRefreshControl object in the ScrollView of webView like this

    let refreshControl = UIRefreshControl()
    refreshControl.addTarget(self, action: #selector(self.refreshWebView(_:)), forControlEvents: UIControlEvents.ValueChanged)
    webView.scrollView.addSubview(refreshControl)
    

    Add func like this

    func refreshWebView(sender: UIRefreshControl) {
        print("refersh")
        webView.loadRequest(NSURLRequest(URL: NSURL(string: "https://google.com")!))
        sender.endRefreshing()
    }
    

    Hope this will help you.

提交回复
热议问题