我有一个NSTimer
我想每秒更新一个标签。我的代码是:
- (IBAction)OnClickEmergencyButton:(id)sender
{
emergencyAlertTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(emergencyTimer) userInfo:nil repeats:YES];
[emergencyAlertTimer fire];
}
- (void)emergencyTimer
{
int i = 0;
_emergencyAlertTriggerTimerLabel.text = [NSString stringWithFormat:@"%d", ++i];
}
当我运行它时,标签最初显示“1”然后停止。
我希望标签每秒不断计数,例如“1”、“2”、“3”……