【问题标题】:create a countdown timer in objective c (iPhone development) [duplicate]在目标c(iPhone开发)中创建倒数计时器[重复]
【发布时间】:2012-03-07 18:25:55
【问题描述】:

可能重复:
How do I use NSTimer

我想创建一个计时器:当用户单击按钮时,计时器启动。 (例如)两秒后,计时器停止/重置并执行操作。

我一直在寻找 NSTimer,但没有找到正确的使用方法,以及如何以正确的方式进行设置。

提前感谢您的帮助!

【问题讨论】:

标签: iphone objective-c ios timer countdowntimer


【解决方案1】:
- (IBAction)buttonPressed:(id)sender
{
    [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(timerExpired) userInfo:nil repeats:NO];
}

- (void)timerExpired
{
    NSLog(@"Your two seconds are up!");
}

【讨论】:

  • @Dan 目的不是调用 NSLog,而是演示如何按照问题所述创建一次性 NSTimer。你有一个你推荐的例子吗?分享你的答案。
猜你喜欢
  • 1970-01-01
  • 2019-07-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-11-13
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多