Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
可能重复: 如何使用 NSTimer
我想创建一个计时器:当用户单击按钮时,计时器启动。在(例如)两秒后,计时器停止/重置并执行操作。
我一直在寻找 NSTimer ,但没有找到正确的使用方法,以及如何以正确的方式进行设置。
在此先感谢您的帮助!
- (IBAction)buttonPressed:(id)sender { [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(timerExpired) userInfo:nil repeats:NO]; } - (void)timerExpired { NSLog(@"Your two seconds are up!"); }