当用户按下刷新按钮时,我想用活动指示器替换刷新按钮,并且在刷新 tableview 后,我想将其更改回刷新按钮。但是当我按下刷新按钮时,它并没有变为活动指示器,而是刷新按钮突出显示,直到数据重新加载完成。
代码如下。我错过了什么?
-(void) reloadNewsStarted{
UIActivityIndicatorView *activityIndicatorRightBarItem = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(0, 0, 20, 20)];
[activityIndicatorRightBarItem startAnimating];
UIBarButtonItem *activityItem = [[UIBarButtonItem alloc] initWithCustomView:activityIndicatorRightBarItem];
[activityIndicatorRightBarItem release];
self.navigationItem.rightBarButtonItem = activityItem;
[activityItem release];
[self reloadNewsEnded];
}
-(void) reloadNewsEnded {
//reload data process
UIBarButtonItem *reloadNewsBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(reloadNewsStarted)];
reloadNewsBtn.style = UIBarButtonItemStyleBordered;
self.navigationItem.rightBarButtonItem = reloadNewsBtn;
[reloadNewsBtn release]; }