首页 > 其他 > 详细

NSTimer启动失效的解决方案

时间:2014-02-04 10:54:40      阅读:398      评论:0      收藏:0      [点我收藏+]

今天突然试了一下timer在线程中启动,果然不行,看了一下之前调研过的文章,解决方案就是放在主线程或者放在runloop即可




- (void)viewDidLoad
{
    [super viewDidLoad];
    
	dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        
        dispatch_async(dispatch_get_main_queue(), ^{
            NSTimer *time =  [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(test) userInfo:Nil repeats:YES];
        });
        
//        [[NSRunLoop currentRunLoop] addTimer:time forMode:NSDefaultRunLoopMode];
//        [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:INTMAX_MAX]];
//        [time fire];
    });
}

- (void)test{
    NSLog(@"11");
}


NSTimer启动失效的解决方案

原文:http://blog.csdn.net/ioswyl88219/article/details/18911319

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