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];
 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值