Reputation: 22926
If I use:
[NSTimer scheduledTimerWithTimeInterval:.1 target:self selector:@selector(myMethod) userInfo:nil repeats:YES];
How can I invalidate this, as it's a class method I don't have access to a pointer to it?
Upvotes: 0
Views: 145
Reputation: 2148
You can make something like this:
[NSTimer scheduledTimerWithTimeInterval:.1 target:self selector:@selector(myMethod:) userInfo:nil repeats:YES];
(note ":" after myMethod)
- (void) myMethod: (id) sender
{
if ([sender isKindOfClass:[NSTimer class]])
{
NSTimer* timer = (NSTimer*) sender;
[timer invalidate];
}
}
Upvotes: 1
Reputation: 237060
It's a class method that returns a timer. You invalidate that timer.
Upvotes: 1