I have a button and, when pressed, it downloads several images from the web in order to display them in another view. However, at the moment, when I press the button, the button goes to its highlighted state and seems to get stuck there while the images download (and essentially the next view is prepared). I’m not fussed about the button being stuck in highlighted mode (in fact I prefer it that way).
However, what I would like is for a UIActivityView to be displayed on the view where the button is displayed while the next view loads (and the images are downloaded from the web, as this takes a while)…How would I go about implementing this logically?
Thanks,
Jack
I assume you’re using NSURLConnection to connect and download the images? If this is the case, you would want to use an approach like this:
In IB, place a UIActivityIndicatorView on your view where you’d like it and define its style in its Attributes panel. Tell it to Hide When Stopped. And be sure to link it with your code in the owner’s header file.
and
When you create your NSURLConnection and begin the request, tell the indicator to begin animation with
[indicator startAnimation];. If you don’t want your button on screen, you can remove it from the superview if you like.Once you’re done downloading, you can tell the indicator
[indicator stopAnimation](and add your button back if you had removed it earlier) in your- (void)connectionDidFinishLoading:(NSURLConnection *)connectionmethod.If you are downloading the images without using NSURLConnection, this of course would be different, but logically it should be the same approach. Though I agree with David that this should probably be done on a background thread