iOS定时器(NSTimer)

来源:互联网 发布:淘宝应用开发 编辑:程序博客网 时间:2024/05/16 09:59

1、注册过的定时器

 

    @property(nonatomic,weak)NSTimer *timer;//

//注册定时器

    self.timer = [NSTimerscheduledTimerWithTimeInterval:1target:selfselector:@selector(showCount)userInfo:nilrepeats:YES];

//停止定时器

    [self.timerinvalidate];



2、未注册过的定时器

//这是一个未注册的定时器使用的时候要特别注意

    self.timer = [NSTimertimerWithTimeInterval:1target:selfselector:@selector(showText)userInfo:nilrepeats:YES];

    [[NSRunLoopcurrentRunLoop] addTimer:self.timerforMode:NSDefaultRunLoopMode];




转载请注明出处:http://blog.csdn.net/sevenquan


0 0