Well, what you could do is: anytime you call [object performSelector: withObject: afterDelay:] , just add the line above. You could create a method that handles this for you. For example:
- (void)performSelectorOnce:(SEL)selector withObject:(id)object afterDelay:(NSTimeInterval)delay { [NSObject cancelPreviousPerformRequestsWithTarget:object selector:selector object:object]; [self performSelector:selector withObject:object afterDelay:delay]; }
and than you ever use [object performSelector: withObject: afterDelay:] , just replace it with [self performSelectorOnce: withObject: afterDelay:];
If you want to use this in several objects, than you could create an NSObject category and add a method there.
Let me know if this works for you.
Mihai fratu
source share