也谈NSTimer的使用

先来看NSTimer invalidate()方法的官方说明

Stops the timer from ever firing again and requests its removal from its run loop.

This method is the only way to remove a timer from an NSRunLoopobject. The NSRunLoop object removes its strong reference to the timer, either just before the invalidate method returns or at some later point.

If it was configured with target and user info objects, the receiver removes its strong references to those objects as well.

说的就是该方法会将runloop之中移除对timer的强引用,(如果参数中设置了target或者user info 对象,也一样移除对timer的强引用)

- (void)stop{
    [_timer invalidate];
    _timer = nil;
}

 

你可能感兴趣的:(IOS随笔札记)