当前位置: 代码迷 >> Iphone >> iphone定时器步骤
  详细解决方案

iphone定时器步骤

热度:105   发布时间:2016-04-25 06:40:34.0
iphone定时器方法

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.

+ (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?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];
?

?

?

  相关解决方案