NSTimer类方法和无效



如果我使用:

[NSTimer scheduledTimerWithTimeInterval:.1 target:self selector:@selector(myMethod) userInfo:nil repeats:YES]; 

由于这是一个类方法,我无法访问指向它的指针,我如何使其无效?

您可以制作这样的东西:

[NSTimer scheduledTimerWithTimeInterval:.1 target:self selector:@selector(myMethod:) userInfo:nil repeats:YES];

(myMethod后的注释":")

- (void) myMethod: (id) sender
{
    if ([sender isKindOfClass:[NSTimer class]])
    {
        NSTimer* timer = (NSTimer*) sender;
        [timer invalidate];
    }
}

这是一个返回计时器的类方法。你使计时器失效。

最新更新