Other then setting UIGestureRecognizers in a Controller:
UISwipeGestureRecognizer *swipeGesture = [[UISwipeGestureRecognizer alloc]
initWithTarget:v action:@selector(handleSwipe:)];
swipeGesture.direction= UISwipeGestureRecognizerDirectionUp;
[v addGestureRecognizer:swipeGesture];
And making a method in a view available
-(void)handleSwipe:(UISwipeGestureRecognizer *)sender {
NSLog(@"Swipe detected");
}
Is there anything else needed? If not, what am i missing please? When gesture is simulated, NSlog is not printing
Edit
I see from your recent question that you are also using a pan gesture recognizer. Gesture recognizers don’t really know how to play well with each-other without instruction. You have two main options
1) One or the other:
The pan only fires if the touch is not a swipe. or-
2) Both at the same time:
Conform the the
UIGestureRecognizerDelegateprotocol.Set the delegates:
And implement the method:
Original
Right now you are setting your view
vas the target of the recognizer, so essentially when the swipe is detected the recognizer calls:It seems more likely that both of your methods are in a view controller. If that’s the case then the init method should look like this:
Since
vis the intended target and with that in mind your code is fine; I would think the next most likely cause is that your first chunk of code runs before the viewvloads. i.e. the code is not inviewDidLoadaftervalready exists. If you’re unsure a simple log will confirm it’s existence:If that proves to be a dead-end we will definitely require more info on this view
v. What is it’s superclass? Are there other recognizers on it? How is it added to theview?