Pull to update UIWebView?

I am trying to update on a UIWebView to load a website. UIWebView code is pretty simple

 import UIKit class ViewController: UIViewController { @IBOutlet weak var WebView: UIWebView! override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. let URL = NSURL(string: "https://the url/") WebView.loadRequest(NSURLRequest(URL: URL!)) } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } } 

Does anyone have some kind of example, because no matter what I'm looking for, I only found pull to update in tableviews, and I'm not sure if it will work with this either.

Thanks.

Update 1. After the Sohil suggestion, the code is as follows

 import UIKit class ViewController: UIViewController { @IBOutlet weak var WebView: UIWebView! @IBOutlet weak var scrollView: UIScrollView! override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. let URL = NSURL(string: "https://iremember.gr/") WebView.loadRequest(NSURLRequest(URL: URL!)) } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. func scrollViewWillEndDragging(scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) { if (scrollView.contentOffset.y < 0){ //reach top print("Reach Top") WebView.reload() } else { print("nothing") } } } } 

But it doesn't even print β€œnothing” when I try to restart it.

+5
source share
1 answer

You can use UIScrollView to accomplish this task. First, you need to check if the UIWebView user is pulling β€œUp” or β€œDown”, since the code below will help to view and then reload the UIWebView :

 func scrollViewWillEndDragging(scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) { if (scrollView.contentOffset.y < 0){ //reach top print("Reach Top") webView.reload() } } 

Make sure you add the delegate to the UIScrollView :

 webView.scrollView.delegate = self 

Hope this helps!

+6
source

Source: https://habr.com/ru/post/1237094/


All Articles