iphone定时器方法
scheduledTimerWithTimeInterval:target:selector:userInfo:repeats:
Creates and returns a new NSTimer
+ (NSTimer *)scheduledTimerWithTimeInterval:(NSTimeInterval) seconds target:(id) target selector:(SEL) aSelectoruserInfo:(id) userInfo repeats:(BOOL) repeats
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. If NO
, the timer will be invalidated after it fires.
Return Value
A new NSTimer
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];