首页 > 其他 > 详细

RunLoop(基本操作)

时间:2014-03-06 00:48:54      阅读:452      评论:0      收藏:0      [点我收藏+]

bubuko.com,布布扣

 

基本概念

bubuko.com,布布扣

 

bubuko.com,布布扣
-(void)runTimerInThread
{
    //NSAutoreleasePool,没的用
    [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(doSth:) userInfo:self repeats:YES];
    
    //1.以上方法自动把NSTimer添加到RunLoop里面
    
    NSTimer* timer=[NSTimer timerWithTimeInterval:1.0 target:self selector:@selector(doSth:) userInfo:self repeats:YES];
    
    //2.以上方法不会自动NSTimer添加到RunLoop里面
    [[NSRunLoop currentRunLoop]addTimer:timer forMode:NSDefaultRunLoopMode];
    //要手动加入runLoop,额额,类方法就写入了 addTimer:timer forMode:NSDefaultRunLoopMode;
    
    
    [[NSRunLoop currentRunLoop]run];
    //这很重要,把定时器的线程加入运行回环runloop才会使线程处于活跃状态

}
bubuko.com,布布扣

定时器要加入runLoop才可以正常运行,但是要保证定时器的精确度,必须在不堵塞的多线程下进行

 

 [self performSelectorInBackground:@selector(runTimerInThread) withObject:nil];

当然,你可以用CGD技术来处理多线程任务的

RunLoop(基本操作),布布扣,bubuko.com

RunLoop(基本操作)

原文:http://www.cnblogs.com/MrIOS/p/3583472.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!