NSTimer scheduledTimerWithTimeInterval与timerWithTimeInterval、initWithFireDate的区别
2015-05-06 14:20
573 查看
A timer object can be registered in only one run loop at a time, although it can be added to multiple run loop modes within that run loop. There are three ways to create a timer:
Use the
method to create the timer and schedule it on the current run loop in the default mode.
Use the
method to create the timer object without scheduling it on a run loop. (After creating it, you must add the timer to a run loop manually by calling the
of the corresponding
Allocate the timer and initialize it using the
(After creating it, you must add the timer to a run loop manually by calling the
of the corresponding
Once scheduled on a run loop, the timer fires at the specified interval until it is invalidated. A non-repeating timer invalidates itself immediately after it fires. However, for a repeating timer, you must invalidate the timer object yourself by calling its
Calling this method requests the removal of the timer from the current run loop; as a result, you should always call the
from the same thread on which the timer was installed. Invalidating the timer immediately disables it so that it no longer affects the run loop. The run loop then removes the timer (and the strong reference it had to the timer), either just before the
returns or at some later point. Once invalidated, timer objects cannot be reused.
Use the
scheduledTimerWithTimeInterval:invocation:repeats:or
scheduledTimerWithTimeInterval:target:selector:userInfo:repeats:class
method to create the timer and schedule it on the current run loop in the default mode.
Use the
timerWithTimeInterval:invocation:repeats:or
timerWithTimeInterval:target:selector:userInfo:repeats:class
method to create the timer object without scheduling it on a run loop. (After creating it, you must add the timer to a run loop manually by calling the
addTimer:forMode:method
of the corresponding
NSRunLoopobject.)
Allocate the timer and initialize it using the
initWithFireDate:interval:target:selector:userInfo:repeats:method.
(After creating it, you must add the timer to a run loop manually by calling the
addTimer:forMode:method
of the corresponding
NSRunLoopobject.)
Once scheduled on a run loop, the timer fires at the specified interval until it is invalidated. A non-repeating timer invalidates itself immediately after it fires. However, for a repeating timer, you must invalidate the timer object yourself by calling its
invalidatemethod.
Calling this method requests the removal of the timer from the current run loop; as a result, you should always call the
invalidatemethod
from the same thread on which the timer was installed. Invalidating the timer immediately disables it so that it no longer affects the run loop. The run loop then removes the timer (and the strong reference it had to the timer), either just before the
invalidatemethod
returns or at some later point. Once invalidated, timer objects cannot be reused.
相关文章推荐
- NSTimer scheduledTimerWithTimeInterval与timerWithTimeInterval、initWithFireDate的区别
- scheduledTimerWithTimeInterval和timerWithTimeInterval的区别
- scheduledTimerWithTimeInterval与timerWithTimeInterval的区别
- [NSTimer scheduledTimerWithTimeInterval: target: selector: userInfo: repeats:NO陷阱
- 以+scheduledTimerWithTimeInterval... 的方式触发的 timer,在滑动页面上的列表时, timer 会暂定回调,为什么?如何解决?
- 以+scheduledTimerWithTimeInterval...的方式触发的timer,在滑动页面上的列表时,timer会暂定回调,为什么?如何解决?
- scheduledTimerWithTimeInterval使用方法
- scheduledTimerWithTimeInterval
- ios 定时器scheduledTimerWithTimeInterval
- date('Y-m-d H:i:s',time()) 与 date('Y-m-d h:i:s',time())区别是什么
- SQL datetime,smalldatetime、datetime2,date,time,datetimeoffset 区别
- Timer与ScheduledExecutorService的使用和区别
- 使用quartz时,遇见 "missed their scheduled fire-time"
- [IOS]关于 initWithNibName 和 loadNibNamed 的区别和联系
- PHP :time(),date(),mktime()区别 【转】
- initWithCoder: 与initWithFrame:的区别
- initWithFrame和initWithCoder的区别
- 关于 initWithNibName 和 loadNibNamed 的区别和联系
- UIView初始化:initWithFrame与initWithCoder的区别
- ScheduledExecutorService 的 scheduleAtFixedRate 和 scheduleWithFixedDelay 两个方法的区别