我已經實現了風格UIBarSystemItem的刷新按鈕,每當按下該按鈕時它將被禁用10秒。倒計時刷新按鈕
我想通過顯示啓用之前剩下的時間來進一步改進它。什麼是最快捷的方法呢?
許多在此先感謝。
無論何時按下按鈕,都會調用。
-(void)refreshButton {
[self performSelector:@selector(enableRefreshButton) withObject:nil afterDelay:10];
self.navigationItem.rightBarButtonItem.enabled = NO;
}
-(void)enableRefreshButton {
self.navigationItem.rightBarButtonItem.enabled = YES;
}
編輯:刷新按鈕的風格UIBARSystemItemRefresh。
我目前這樣做的答案表明我使用NSTimer。該按鈕確實啓用並相應地禁用,但文本不會更改。
@inteface ... {
int count;
}
-(void)viewDidLoad{
UIBarButtonItem *refresh = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(refreshButtonPressed)];
self.navigationItem.rightBarButtonItem = refresh;
}
-(void)refreshButtonPressed {
//do something here...
count = 10;
self.myTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(updateTimeLeft) userInfo:nil repeats:YES];
}
-(void)updateTimeLeft{
count --;
NSLog(@"%i", count);
self.navigationItem.rightBarButtonItem.title = [NSString stringWithFormat:@"%i", count];
self.navigationItem.rightBarButtonItem.enabled = NO;
if (count == 0) {
self.navigationItem.rightBarButtonItem.enabled = YES;
[self.myTimer invalidate];
}
}
我可以使用title
屬性與UIBarButtonSystemItem?
使用self.navigationItem.rightBarButtonItem.title屬性來更改欄按鈕的標題 – DShah
經過我更新的答案... – DShah