码迷,mamicode.com
首页 > 移动开发 > 详细

ios 之定时器的使用的技巧(结合runloop)使用

时间:2016-05-13 10:11:41      阅读:191      评论:0      收藏:0      [点我收藏+]

标签:

   1.在项目中要使用到定时器,但是遇到了问题就是无法关闭定时器的,在网上找了资料才发生了原来定时器是要结合runloop的使用一起来的呀,不然是无法关闭定时器的使用的

    self.timer1 = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(mythod1) userInfo:nil repeats:YES];

        //将定时器加入到当前的runloop里面

        [[NSRunLoop currentRunLoop]addTimer:self.timer1 forMode:NSRunLoopCommonModes];

      关闭定时器: [self.timer1 setFireDate:[NSDate distantFuture]];

  定时器失效: [self.timer1 invalidate];

 希望对帮助!!!

 

 

   

   

ios 之定时器的使用的技巧(结合runloop)使用

标签:

原文地址:http://www.cnblogs.com/zhufeng1994/p/5486099.html

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