So I recently ran into a snag while trying to implement a UIActivityIndicatorView. There's a great and simple explanation of how to do it on the Apple Developer forums. This is how you're supposed to do it: you tell the UIActivityIndicatorView what method should be run in between starting animation and stopping animation.
Anyway... I needed a way to start a UIActivityIndicatorView when a view was loaded and then be able to hide it, without the use of threads. However, I couldn't find any good solutions. So this is what ended up working for me:
In the view you want to have the UIActivityIndicatorView to show up in, go to your interface (.h) file and define the UIActivityIndicatorView:
Now open up your NIB (.xib) file in Interface Builder. Plop a UIActivityIndicatorView onto your view and place it where you want:
Go ahead and make the connection to the UIActivityIndicatorView from the IBOutlet we just defined:
Now, with the UIActivityIndicatorView selected, go to the Attributes Inspector. There, make sure the "Hide When Stopped" and "Animating" checkboxes are checked:
Save your NIB and go to your view's implementation (.m) file. What we've done so far is set up a UIActivityIndicatorView to show up as soon as your view loads and begin spinning, but now we need to stop it when we want. So now just tell the UIActivityIndicatorView to stop animating when appropriate: