Начиная с iOS 5 с введением ARC вам больше не нужно сохранять.
Решение можно получить, как объяснил @cagreen, а refreshButtonItem можно сохранить как свойство класса, а также loadingButton и loadingView.
В вашем интерфейсе объявите:
@property (strong, nonatomic) UIBarButtonItem *refreshButton;
@property (strong, nonatomic) UIBarButtonItem *loadingButton;
@property (strong, nonatomic) UIActivityIndicatorView *loadingView;
Инициализация loadButton и loadingView в вашем методе viewDidLoad:
self.loadingView = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(0, 0, 20, 20)];
self.loadingButton = [[UIBarButtonItem alloc] initWithCustomView:self.loadingView];
Затем, чтобы показать загрузочный счетчик, вы можете просто сделать:
// Shows loading button
- (void)showLoadingView {
// Keep reference to right bar button
if (self.navigationItem.rightBarButtonItem) {
self.refreshButton = self.navigationItem.rightBarButtonItem;
}
// Start animating and assign loading button to right bar button
[self.loadingView startAnimating];
self.navigationItem.rightBarButtonItem = self.loadingButton;
}
И скрыть:
// Hides loading button
- (void)hideLoadingView {
[self.loadingView stopAnimating];
self.navigationItem.rightBarButtonItem = self.refreshButton;
}