Accessing a selector only once per touch gesture
I've a reload开发者_JS百科 method which handles with highly sensitive core data and I want to implement, that the method can not be executed in parallel.
Is there a simply way to implement something like that?
Update
Maybe it's a different problem.
So I've a pinch-gesture and when a user is doing this gesture I want to execute a method only ONCE!
BUT if I'm simulating it right now in the iOS simulator, the method execution starts when a minimal pinch gesture is recognized and is fired as long as the user holds this pinch gesture.
Is this the default usage?!?!? How can I edit it, that the method is only fired once per pinch gesture independent of how long the user is holding this gesture etc.
Yes there is. Check out the @synchronized
directive: http://developer.apple.com/library/mac/#documentation/cocoa/conceptual/ObjectiveC/Chapters/ocThreading.html
andi1984,
Of course, you could require that the method only execute on the main thread. As in this example:
- (void) sensitiveMethod {
// If necessary, rethrow on the main queue.
if (!NSThread.isMainThread) {
[[NSOperationQueue mainQueue] addOperationWithBlock: ^{
[self sensitiveMethod];
}];
return;
}
// body of your sensitive method here.
} // sensitiveMethod
Andrew
精彩评论