0

I created one view inside my application in that again i created ten views like a grid and i added UITapGestureRecogniser on ten views,if the user tap on one of the view in grid i will call a method where based on its tag value I will create a new view instance of a particular class.But i am getting problem if the user taps on two views at a time or in the difference of fraction of seconds ,then that method is called two times .It is creating problem inside my application.i need solution for this i am not getting any solution what to do.Can any one know this handle please help me as soon as possible.

Thanks &Regards swathi

santhu
  • 4,796
  • 1
  • 21
  • 29
  • can you be a little more specific about what you are doing in that method? – santhu Dec 23 '13 at 18:17
  • When that method is called, inside that method disable events of window or application, so that it wont receive events untill you later enable it. – santhu Jan 01 '14 at 08:25

1 Answers1

0

I'd just create a boolean, thats set to NO in every method called by these views.

At the end of the method, set it to YES

-(void)view1tapped{
       BOOL shouldRecognizeTap = enabled;
       self.enabled = NO;
       if (shouldRecognizeTap){
               // do your stuff here
       }
       self.enabled = YES;
} 

-(void)view2tapped{
       BOOL shouldRecognizeTap = enabled;
       self.enabled = NO;
       if (shouldRecognizeTap){
               // do your stuff here
       }
       self.enabled = YES;
} 

Also, in your gestureRecognizer delegate method, I hope you are checking for recognizer state like this

-(void) handleTapGesture:(UIGestureRecognizer *) sender {
    if (sender.state != UIGestureRecognizerStateEnded)  // <---
        return;  

    sender.enabled = NO // (or disable all the other gesture recognizers).
    // do your stuff here   
    sender.enabled = YES;
}
Nitin Alabur
  • 5,812
  • 1
  • 34
  • 52