David David - 1 year ago 171
Swift Question

Xcode: WebView refreshes/reloads after endRefreshing()

I have an iOS app build with Xcode and Swift.

When I pull to refresh the activityIndicator spins.
When I release the animation/spin will stop immediately but the website only refreshes/reloads after ca. 3/4-1 seconds.

Is there a way to show the animation/spin wheel till the end of refreshing?
This is my code:

func pullToRefresh() {
// NSURLCache.sharedURLCache().removeAllCachedResponses()
func addRefreshControl() {
refreshControl = UIRefreshControl()
refreshControl.attributedTitle = NSAttributedString(string: "Einen Moment bitteā€¦")
refreshControl.addTarget(self, action: #selector(FirstViewController.pullToRefresh), forControlEvents:.ValueChanged)
refreshControl.tintColor = UIColor.blackColor()

Answer Source

You need to call the endRefreshing method of UIRefreshControl in delegate method of UIWebViewDelegate like this

override func viewDidLoad() {
    self.webView.delegate = self

func webViewDidFinishLoad(webView: UIWebView) {

Also remove self.refreshControl.endRefreshing() from pullToRefresh method.

Hope this will help you.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download