NSTimer 简单用法

  1. // 安装timer(注册timer)  
  2.     NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval: 5// 当函数正在调用时,及间隔时间到了 也会忽略此次调用  
  3.                                              target: self  
  4.                                            selector: @selector(handleTimer:)  
  5.                                            userInfo: nil  
  6.                                             repeats: YES]; // 如果是NO 不重复,则timer在触发了回调函数调用完成之后 会自动释放这个timer,以免timer被再一次的调用,如果是YES,则会重复调用函数,调用完函数之后,会将这个timer加到RunLoop中去,等待下一次的调用,知道用户手动释放timer( [timer invalidate];)。  


[cpp]  view plain copy
  1. - (void) handleTimer: (NSTimer *) timer // timer的回调函数  
  2. {  
  3.     //在这里进行处理  
  4.     NSLog(@"1");  
  5.     
  6. }  



[cpp]  view plain copy
  1. //    [timer invalidate]; // 这个函数将timer从当前的RunLoop中remove掉,必须在timer安装的线程中调用这个函数。  

[cpp]  view plain copy
  1. [timer fire];// 可以通过fire这个方法去触发timer,即使timer的firing time没有到达  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值