iphone定时器方法
scheduledTimerWithTimeInterval:target:selector:userInfo:repeats:
Creates and returns a new NSTimer object and schedules it on the current run loop in the default mode.
Parameters
- seconds
-
The number of seconds between firings of the timer. If seconds is less than or equal to
0.0, this method chooses the nonnegative value of 0.1 milliseconds instead.
target
-
The object to which to send the message specified by aSelector when the timer fires. The target object is retained by the timer and released when the timer is invalidated.
aSelector
-
The message to send to target when the timer fires. The selector must have the following signature:
- (void)timerFireMethod:(NSTimer*)theTimer
The timer passes itself as the argument to this method.
userInfo
-
The user info for the timer. The object you specify is retained by the timer and released when the timer is invalidated. This parameter may be
nil.
repeats
-
If
YES, the timer will repeatedly reschedule itself until invalidated. IfNO, the timer will be invalidated after it fires.
Return Value
A new NSTimer object, configured according to the specified parameters.
Discussion
After seconds seconds have elapsed, the timer fires, sending the messageaSelector to target.
定义定时器例子:
NSTimer *timer=[NSTimer scheduledTimerWithTimeInterval:0.01
target:self
selector:@selector(showTime)
userInfo:nil
repeats:YES];
结束定时器例子:
[timer invalidate];
本文介绍如何使用iPhone上的NSTimer创建定时任务。通过scheduledTimerWithTimeInterval方法可以设置目标对象、触发间隔、回调方法等参数实现重复或一次性触发的任务。示例展示了如何启动及停止定时器。
255

被折叠的 条评论
为什么被折叠?



