现在的位置: 首页 > 综合 > 正文

定时器NSTimer的简单使用和停止

2013年12月11日 ⁄ 综合 ⁄ 共 395字 ⁄ 字号 评论关闭

http://blog.sina.com.cn/s/blog_8d759e760100ute1.html

NSTimer *timer


1.运行一次自动停止
timer =  [NSTimer scheduledTimerWithTimeInterval:3.0 target:self selector:@selector(function:) userInfo:nilrepeats:NO];
这样timer运行一次就会自动停下来的

2.重复运行在方法中停止
timer =  [NSTimer scheduledTimerWithTimeInterval:3.0 target:self selector:@selector(function:) userInfo:nil repeats:YES];
就会每三秒运行一次function:

在function:中加入 [timer invalidate];语句可在内部令其停止

抱歉!评论已关闭.