Lin*_*rld 3 iphone xcode nstimer nstimeinterval
我想使用NSTimer如何在程序中初始化定时器产生2秒的延迟?
dav*_*com 12
这里有多种选择.
如果您只想延迟2秒,可以使用sleep()函数
#include<unistd.h>
...
sleep(2);
Run Code Online (Sandbox Code Playgroud)
或者您可以像这样使用NSTimer
[NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(fireMethod) userInfo:nil repeats:NO];
Run Code Online (Sandbox Code Playgroud)
在你的课堂上,你将有一个定义为的方法
-(void)fireMethod
{
//Do stuff
}
Run Code Online (Sandbox Code Playgroud)