scheduledTimerWithTimeInterval和timerWithTimeInterval的区别

原英文地址:http://blog.csdn.net/leikezhu1981/article/details/45535329

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:

一个timer对象一次只能在唯一的运行循环中注册,尽管在那个运行循环中timer对象能被添加多种运行循环模式。有三种方式创建一个timer。

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 invalidate method. Calling this method requests the removal of the timer from the current run loop; as a result, you should always call the invalidate method 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 theinvalidate method returns or at some later point. Once invalidated, timer objects cannot be reused.

一旦这个timer对象安排进一个运行循环,timer对象在特定的间隔后就会执行除非它被打爆了(哈哈,就是无效了),一个非反复的timer在它执行一次后立刻就会失效了,然而,对于一个反复的方法,你必须主动通过调用它的无效方法:invalidate来打爆那个timer对象,调用那个方法就是请求把那个timer对象从那个目前的运行循环中移除。因此,你应该总是从timer被安装在的线程处调用那个”打爆“方法,“打爆”那个timer立即废了它,所以它不会影响那个运行循环。运行循环要么仅仅就在那个打残方法返回或者就是在那晚一点,运行循环于是就移除那个timer并且移除了运行时对那个timer的强引用。timer一旦被打爆,它就不能被重用了。


总而言之:scheduledTimerWithTimeInterval  会自动运行timer

timerWithTimeInterval需要加到运行循环里面


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值