Re: Show UIActivityIndicatorView asynchronously

On Thu, 28 Apr 2011 06:26:17 -0400, Philip Vallone <philip.vallone@xxxxxxxxxxx>
>I have a UIViewController that can take a few seconds to load. The view
>searches an XML file and eventually displays the resuts. I want to show a
>UIActivityIndicatorView while the view loads. Unfortunately they are on the
>same thread. How can I get the UIActivityIndicatorView to display befiore the
>view loads? With the below code, the UI freezes up (indicator never shows)
>until the search is done.
>[self.activityIndicator startAnimating];
>TitleSearchResultsViewController *controller =
>[[TitleSearchResultsViewController alloc]
>initWithNibName:@"TitleSearchResultsViewController" bundle:nil];
>[controller setTitle:@"Search Results"];

Use delayed performance. Here's sample code from one of my own apps:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
*)indexPath {
[act startAnimating];
// jump out using delayed performance, to give us a chance to start
animating the UIActivityIndicatorView
[self performSelector:@selector(showItemsForRow:) withObject:indexPath

And then showItemsForRow inits the view controller and loads its view in the
usual way. m.

matt neuburg, phd = matt@xxxxxxxxxxx, <>
A fool + a tool + an autorelease pool = cool!
Programming iOS 4!

Cocoa-dev mailing list (Cocoa-dev@xxxxxxxxxxxxxxx)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)

Help/Unsubscribe/Update your Subscription:

This email sent to maillists@xxxxxxxxx