0

I have this code:

UISwipeGestureRecognizer *recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(rightSwipeHandle:)];
[recognizer setNumberOfTouchesRequired:1];
[view1 addGestureRecognizer:recognizer];
[view2 addGestureRecognizer:recognizer];
[view3 addGestureRecognizer:recognizer];
[recognizer release];

- (void)rightSwipeHandle:(UISwipeGestureRecognizer*)gestureRecognizer{ //do something}

it recognizes swipe only in view3, why? and how can I solve this problem? Should I do a new swipegesture for every views? but I have 20 views.

Ilanchezhian
  • 17,426
  • 1
  • 53
  • 55
cyclingIsBetter
  • 17,447
  • 50
  • 156
  • 241

1 Answers1

2

If you have 20 views, they might be stored in an array or something? If yes, have you tried something like this?

 for (unsigned i = 0; i < [yourViewsArray count]; i++){
    UIView *view = [yourViewsArray objectAtIndex:i]; 
    UISwipeGestureRecognizer *recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(rightSwipeHandle:)];
    [recognizer setNumberOfTouchesRequired:1];
    [view addGestureRecognizer:recognizer];
    [recognizer release];
 }

With this you add a new recognizer to every view

pmk
  • 1,897
  • 2
  • 21
  • 34
  • my fault, i will edit that, anyway you could set up a gesturerecognizer for all views like that – pmk Jan 04 '12 at 10:39