[英]Countdown Timer starts from 4 to 1
The timer starts a countdown of “4…3…2…1…” when I start to play the Quiz. 当我开始玩测验时,计时器开始倒数“ 4…3…2…1…”。 I want to add this countdown in first question of quiz.
我想在测验的第一个问题中添加此倒数计时。 After countdown the first question display.
倒数后显示第一个问题。
Can any one help me please 有人可以帮我吗
I m trying to do this but i did'nt get format for countdown. 我正在尝试执行此操作,但我没有获取倒数格式。
NSTimer *timer_total = [NSTimer scheduledTimerWithTimeInterval:1.0/10.0 target:self selector:@selector(updateTimer) userInfo:nil repeats:YES];
- (void)updateTimer
{
NSDate *currentDate = [NSDate date];
NSTimeInterval timeInterval = [currentDate timeIntervalSinceDate:startDate_total];
NSDate *timerDate = [NSDate dateWithTimeIntervalSince1970:timeInterval];
self.df_total = [[NSDateFormatter alloc] init];
[self.df_total setDateFormat:@"mm:ss"];
[self.df_total setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0.0]];
NSString *timeString=[self.df_total stringFromDate:timerDate];
self.lbl_total_Timer.text = timeString;
}
you can do like 你可以喜欢
int currentTime;
- (IBAction)start{
currentTime = 5;
lbl=[[UILabel alloc]init];
//creates and fires timer every second
myTimer = [[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(showTime) userInfo:nil repeats:YES]retain];
}
-(void)showTime{
if(currentTime==0)
{
[myTimer invalidate];
myTimer = nil;
}
else{
currentTime--;
lbl.text = [NSString stringWithFormat:@"%.2d", currentTime];
}
NSLog(@"my lable == %@",lbl.text);
}
- (void)viewWillAppear:(BOOL)animated
{
[self start];
[super viewWillAppear:YES];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.