我想用刷新按鈕替換刷新按鈕,當用戶按下刷新按鈕時,刷新桌面視圖後,我想將其更改回刷新按鈕。但是當我按下刷新按鈕時,它不會更改爲活動指示器,但刷新按鈕會突出顯示,直到數據重新加載完成。用UIActivityIndicatorView替換UIBarButtonItem不起作用
代碼如下。我錯過了什麼?
-(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]; }
非常感謝。有用!!! – moon 2010-10-07 10:09:04