【发布时间】:2012-05-26 15:37:26
【问题描述】:
我是 iOS 编程新手。我正在开发单词匹配游戏。在这个游戏中,我需要实现显示分钟和秒的时间计数器。我希望我的游戏开始时我的计时器从 3 分钟开始。现在我想用秒数反向减少这个计时器。我的代码只工作了几秒钟。这是我的代码:
secondsLeft--;
int seconds = (secondsLeft %3600) % 60;
Timerlbl.text = [NSString stringWithFormat:@"%02d",seconds];
if (seconds==0)
{
UIAlertView *pAlert = [[UIAlertView alloc]initWithTitle:@"Sorry!!"
message:@"TimeOver" delegate:self cancelButtonTitle:@"OK"
otherButtonTitles:@"Cancel",nil];
[pAlert show];
[pAlert release];
}
}
在 Viewdidload 我通过计时器调用它..
countDown=[NSTimer scheduledTimerWithTimeInterval:5.0 target:self
selector:@selector(TimeOver) userInfo:nil repeats:YES];
请任何人指导我如何在几分钟和几秒钟内完成。
【问题讨论】:
-
请查看以下链接Count down timer 它也很方便。问候,尼尔
标签: iphone objective-c ios nstimer