Reputation: 25
I already checked the behavior on activity indicator view setting and coded it on a view controller..But still it keeps on spinning...What would be the problem?
I added this
@IBOutlet var Loadebest: UIActivityIndicatorView!
and this
func webViewDidStartLoad(_ : UIWebView) {
Loadebest.startAnimating()
NSLog("Webview is working")
}
func webViewDidFinishLoad(_ : UIWebView) {
Loadebest.stopAnimating()
NSLog("Webview stopped working")
}
But nothing happens...what could be the problem?
Upvotes: 1
Views: 439
Reputation: 1001
problem is that method trigger more than one time. Replace your code with this one:
private var webViewsload = 0
func webViewDidStartLoad(webView: UIWebView) {
self.navigationItem.title = LangData.get("WEB_VIEW_LOADING")
webViewsload += 1
self.updateButtons()
}
func webViewDidFinishLoad(webView: UIWebView) {
webViewsload -= 1;
activitiIndicator.stopAnimating()
if (webViewsload == 0) {
self.navigationItem.title = webView.stringByEvaluatingJavaScriptFromString("document.title");
}
self.updateButtons()
}
Hope this help.
Upvotes: 0
Reputation: 4391
Try:
func webViewDidFinishLoad(_ : UIWebView) {
NSLog("Webview stopped working")
dispatch_async(dispatch_get_main_queue(),{
self.Loadebest.stopAnimating()
})
}
Upvotes: 1
Reputation: 9898
Check in storyboard, you have given delegate to webview.
If you haven't given delegate to webview then webViewDidFinishLoad
will not call and it will not hide spinner.
Upvotes: 0
Reputation: 4222
You need to set the property "hides when stopped" of the activity indicator.
You can do this either using the storyboard, there should be a small checkbox that enable this property in the inspector.
Or in objective C-
Loadebest.hidesWhenStopped = YES;
Upvotes: 0