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

时间:2016-05-13 10:09:38   收藏:0   阅读:243

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

 希望对帮助!!!

 

 

   

   

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

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!