I have the UIBarButtonItem (configurated in interface builder). If a user click this button, the "heavy process" will be started and for better user experience I want to change this button with (UIActivityIndicatorView). I do it in the following way:
self.indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
indicator.hidesWhenStopped = YES;
[self.heavyBarButton initWithCustomView:self.indicator];
[self.indicator startAnimating];
[NSThread detachNewThreadSelector:@selector(animateHeavyProcess) toTarget:self withObject:nil];
animateHeavyProcess:
[self heavyProcess];
[self.indicator stopAnimating];
UIBarButtonItem *originalButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"maximize.png"] style:UIBarButtonItemStylePlain target:self action:@selector(startProcessClick:)];
self.heavyBarButton = originalButton;
[originalButton release];
What happens: after a user clicks the BarButton animation will be started and after processing button disappears. However, I want that the original button will be shown again.