Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swipe gesture iphone

I have some trouble to handle swipe on iPhone, I create in my interface a UISwipeGestureRecognizervar:

UISwipeGestureRecognizer *swipeRecognizer;

and in my controller : viewDidLoad method

- (void)viewDidLoad
{
    [super viewDidLoad];


    // Horizontal swipe
    swipeRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self 
                                                                          action:@selector(swipeMethod:)];
    swipeRecognizer.direction = UISwipeGestureRecognizerDirectionRight | UISwipeGestureRecognizerDirectionLeft; 
    [self addGestureRecognizer:swipeRecognizer];
}

And my method to handle swipe is :

-(void)swipeMethod: (UISwipeGestureRecognizer *) sender
{
    NSLog(@"Swipe!");   
}

When I run my code and do a swipe I got nothing? I'm supposed to get : Swipe!

Thanks.

like image 252
Lekhal Avatar asked Apr 19 '11 14:04

Lekhal


1 Answers

I'm surprised that doesn't crash with an unrecognized selector error. Try adding the recognizer to your view instead of to your view controller:

[self.view addGestureRecognizer:swipeRecognizer]
like image 125
Anomie Avatar answered Jan 20 '23 06:01

Anomie