繁体   English   中英

如何使用NSTimer,启动/停止?

[英]How Do I Use NSTimer, start/stop?

我将如何使用NSTimer每秒进行一次操作?

尼基塔。

用这种方式

-(void)fireTimer{
   [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selected(timeOut:) userInfo:nil repeats:YES];
}

现在,这将每隔1秒调用一次timeOut:选择器,然后在timeOut中:

-(void)timeOut:(NSTimer*)timer{
   static int count = 0;
   count++;
   if(count == 60){
     [timer invalidate]; 
     timer = nil;
   }
}

有很多API。 我希望您想查看https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSTimer_Class/Reference/NSTimer.html

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM