Reputation: 891
I am calling callDailyQuotes
methods on button click. The activityIndicator
starts animating as data is downloaded from the server, but then the activityIndicator
stops animating.
Here is the relevant code:
self.activityIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyle.Gray
self.activityIndicator.startAnimating()
let qualityOfServiceClass = QOS_CLASS_BACKGROUND
let backgroundQueue = dispatch_get_global_queue(qualityOfServiceClass, 0)
dispatch_async(backgroundQueue, {
self.callDailyQuotes()
dispatch_async(dispatch_get_main_queue(), { () -> Void in
})
})
func callDailyQuotes(){
//calling nsurlconnection synchronously
self.activityIndicator.stopAnimating()
}
What's happening that makes the activityIndicator
stop animating?
Upvotes: 1
Views: 592
Reputation: 72750
You have to execute the self.activityIndicator.stopAnimating()
call in the main thread, so my suggestion is to move it in the dispatch_async
you've already added but left empty:
self.activityIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyle.Gray
self.activityIndicator.startAnimating()
let qualityOfServiceClass = QOS_CLASS_BACKGROUND
let backgroundQueue = dispatch_get_global_queue(qualityOfServiceClass, 0)
dispatch_async(backgroundQueue, {
self.callDailyQuotes()
dispatch_async(dispatch_get_main_queue(), { () -> Void in
self.activityIndicator.stopAnimating()
})
})
func callDailyQuotes(){
//calling nsurlconnection synchronously
}
Upvotes: 3