码迷,mamicode.com
首页 > 其他好文 > 详细

NSTimer的使用

时间:2015-09-13 19:51:42      阅读:213      评论:0      收藏:0      [点我收藏+]

标签:

1.创建

NSTimer *_timer;

2.使用

_timer = [NSTimer scheduledTimerWithTimeInterval:0.5f target:self selector:@selector(nextTime) userInfo:nil repeats:YES];
    [[NSRunLoop mainRunLoop] addTimer:_timer forMode:NSRunLoopCommonModes];

3.开启与关闭

-(void)nextTime

{

  //关闭定时器
  [_timer setFireDate:[NSDate distantFuture]];
  //开启定时器
  //[_timer setFireDate:[NSDate distantPast]];

}

4.注销

-(void)dealloc
{
    //释放定时器
    [_timer invalidate];
    _timer = nil;
}

NSTimer的使用

标签:

原文地址:http://www.cnblogs.com/liaods/p/4805396.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!