[IOS]NSTimer启动与停止 (2012-02-03 14:49:06)转载▼
标签: 杂谈 分类: Code
timer = [NSTimer scheduledTimerWithTimeInterval:3.0 target:self selector:@selector(function:) userInfo:nil repeats:NO];
timer运行一次就会自动停下
timer = [NSTimer scheduledTimerWithTimeInterval:3.0 target:self selector:@selector(function:) userInfo:nil repeats:YES];
就会每三秒运行一次function
在function:中加入 [timer invalidate];语句可在内部令其停止
标签: 杂谈 分类: Code
timer = [NSTimer scheduledTimerWithTimeInterval:3.0 target:self selector:@selector(function:) userInfo:nil repeats:NO];
timer运行一次就会自动停下
timer = [NSTimer scheduledTimerWithTimeInterval:3.0 target:self selector:@selector(function:) userInfo:nil repeats:YES];
就会每三秒运行一次function
在function:中加入 [timer invalidate];语句可在内部令其停止
本文深入探讨了iOS开发中NSTimer的基本概念,包括如何使用scheduledTimerWithTimeInterval来启动定时器,以及如何通过invalidate方法来停止定时器。文章详细解释了定时器的运行模式(单次或循环),并提供了实际应用示例。

1104

被折叠的 条评论
为什么被折叠?



