When I call startAnimating on a UIActivityIndicatorView, it doesn't start. Why is this?
[This is a blog-style self-answered question. The solution below works for me, but, maybe there are others that are better?]
When I call startAnimating on a UIActivityIndicatorView, it doesn't start. Why is this?
[This is a blog-style self-answered question. The solution below works for me, but, maybe there are others that are better?]
If you write code like this:
You aren't giving the UI time to actually start and stop the activity indicator, because all of your computation is on the main thread. One solution is to call startAnimating in a separate thread:
Or, you could put your computation on a separate thread, and wait for it to finish before calling stopAnimation.
Ok, sorry seems like I went through my code being blind.
I've ended the Indicator like this:
So after one run, the activityIndicator has been removed completely.
I usually do:
This question is quite useful. But one thing that is missing in the answer post is , every thing that takes long time need to be perform in separate thread not the UIActivityIndicatorView. This way it won't stop responding to UI interface.
If needed, swift 3 version:
All UI elements require to be on main thread
then: