I’m using a UIActivityIndicator inside a UIBarButtonItem to show activity, but the indicator is slow to appear. I’m creating it using
UIActivityIndicatorView *innerActivityIndicator = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(0, 0, 20, 20)];
[innerActivityIndicator startAnimating];
self.activityIndicator = [[UIBarButtonItem alloc] initWithCustomView:innerActivityIndicator];
Then toggling visibility using
if(loading){
[self.navigationItem setRightBarButtonItem:activityIndicator animated:true];
} else {
[self.navigationItem setRightBarButtonItem:nil animated:true];
}
Generally it takes 4 or 5 seconds before it actually appears and I have no idea why. I was originally starting/stopping the animation but this also did not work. I’ve had this problem/effect in two apps now so I must be doing something wrong.
As Mark Adams pointed out, the problem was I was adding and removing the indicator from a background thread using GCD.