Hi all,
I am experimenting with gesture recognizers, but I've run into a problem I just can't figure out on my own. I have a UIViewcontroller with two swipe gesture recognizers, one for left swipe, one for right swipe. While the right swipe works perfectly, the left swipe throws an unrecognized selector exception, even though, apart from the direction, they are configured exactly the same way. Here's my code:
Here is my interface:
and my implementation:
Note that I've only included the methods pertaining what I need to do, it is not the complete implementation of the interface (though most of the others are simly calling their [super].
Questions:
1. Why does this throw unrecognized selector?
2. Why doesn't the setDirection method appear in the docs for UISwipeGestureRecognizer?
3. It seems that it would be possible to set up a single gesture recognizer to handle both directions. How would I know which direction was swiped inside the handler method?
Thanks for any help. It is greatly appreciated.
I am experimenting with gesture recognizers, but I've run into a problem I just can't figure out on my own. I have a UIViewcontroller with two swipe gesture recognizers, one for left swipe, one for right swipe. While the right swipe works perfectly, the left swipe throws an unrecognized selector exception, even though, apart from the direction, they are configured exactly the same way. Here's my code:
Here is my interface:
Code:
@interface SecondViewController : UIViewController {
UISwipeGestureRecognizer *recog_right;
UISwipeGestureRecognizer *recog_left;
}
-(void)handleSwipeGesture:(UIGestureRecognizer *)sender;
-(void)handleLeftSwipeGesture:(UIGestureRecognizer *)sender;
@property(nonatomic,retain) UISwipeGestureRecognizer *recog_right;
@property(nonatomic,retain) UISwipeGestureRecognizer *recog_left;
@end
and my implementation:
Code:
- (void)dealloc
{
[super dealloc];
[recog_left release];
[recog_right release];
}
-(void)handleSwipeGesture:(UIGestureRecognizer *)sender
{
NSLog(@"Swiped Right!");
}
-(void)handleLeftSwipeGesture:(UIGestureRecognizer *)sender
{
NSLog(@"Swiped Left!");
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
//añade recognizer para la derecha
self.recog_right =[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeGesture:)];
[self.view addGestureRecognizer:self.recog_right];
//añade para la izquierda
self.recog_left = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(hanleLeftSwipeGesture:)];
[self.recog_left setDirection:UISwipeGestureRecognizerDirectionLeft];
[self.view addGestureRecognizer:self.recog_left];
}
Note that I've only included the methods pertaining what I need to do, it is not the complete implementation of the interface (though most of the others are simly calling their [super].
Questions:
1. Why does this throw unrecognized selector?
2. Why doesn't the setDirection method appear in the docs for UISwipeGestureRecognizer?
3. It seems that it would be possible to set up a single gesture recognizer to handle both directions. How would I know which direction was swiped inside the handler method?
Thanks for any help. It is greatly appreciated.