Have you seen those iPhone apps with a reload button that switches itself to an animated activity indicator while the reload action is being performed?
Here is how to do that. Place this code on your ViewController:
-
- (void)showReloadButton {
-
UIBarButtonItem *refreshItem = [[UIBarButtonItem alloc]
-
initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh
-
target:self
-
action:@selector(reload:)];
-
self.navigationItem.rightBarButtonItem = refreshItem;
-
[refreshItem release];
-
}
-
-
- (void)showActivityIndicator {
-
UIActivityIndicatorView *activityIndicator =
-
[[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(0, 0, 20, 20)];
-
[activityIndicator startAnimating];
-
UIBarButtonItem *activityItem =
-
[[UIBarButtonItem alloc] initWithCustomView:activityIndicator];
-
[activityIndicator release];
-
self.navigationItem.rightBarButtonItem = activityItem;
-
[activityItem release];
-
}
-
-
- (IBAction) reload {
-
// Do your reload stuff
-
}
Seen here.
