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

timer 在滚动的时候停止了的解决办法

时间:2014-06-04 20:23:05      阅读:228      评论:0      收藏:0      [点我收藏+]

标签:des   c   class   code   a   tar   

方法一:

-(void) viewDidLoad{
[self performSelectorInBackground:@selector(call1) withObject:nil]; 
}

-(void) call1{
timer1 = [NSTimer scheduledTimerWithTimeInterval:3.0 target:self selector:@selector(doSomething) userInfo:nil repeats:NO];

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

}

-(void) call2{
// do something
timer1 invalidate];
timer1 = nil;
}

方法二:

-(void)viewDidAppear:(BOOL)animated {
    NSThread* timerThread =[[NSThread alloc] initWithTarget:self selector:@selector(timerStart)object:nil];
    [timerThread start];}-(void)timerStart
{
    NSAutoreleasePool*pool =[[NSAutoreleasePool alloc] init];
    NSRunLoop* runLoop =[NSRunLoop currentRunLoop];
    timer =[[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(method) userInfo:nil repeats:YES] retain];//一定要retain,不然timerStart执行完后,NSTimer就被释放了。
    [runLoop run];
    [pool release];}-(void)viewDidDisappear:(BOOL)animated {
    [super viewDidDisappear:animated];
    [timer invalidate];}
方法三:
timer = [NSTimer timerWithTimeInterval:5.0 target:self selector:@selector(SendHeartBeat) userInfo:nil repeats:YES];
 [[NSRunLoop mainRunLoop] addTimer:heartTimer forMode:NSDefaultRunLoopMode];

timer 在滚动的时候停止了的解决办法,布布扣,bubuko.com

timer 在滚动的时候停止了的解决办法

标签:des   c   class   code   a   tar   

原文地址:http://www.cnblogs.com/ios8023/p/3759435.html

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