Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UISwipeGestureRecognizer called twice?

I'm having problem with UISwipeGestureRecognize called twice, I created tabbarcontroller based application which having 4 tabs. Each tab having UINavigationController under that UIViewController, there i have impelemented below code in 3rd tab.

UISwipeGestureRecognizer *swipeLeft =[[UISwipeGestureRecognizer alloc]
        initWithTarget:self action:@selector(didSwipeLeft:)];
swipeLeft.direction=UISwipeGestureRecognizerDirectionLeft;
swipeLeft.numberOfTouchesRequired = 1;
[self.view addGestureRecognizer:swipeLeft];
[swipeLeft release];

- (void) didSwipeLeft:(UISwipeGestureRecognizer *)sender {
    NSLog(@"Left..");
    if ((sender.state == UIGestureRecognizerStateEnded)) {
        [self.tabBarController setSelectedIndex:0];
    }
}

When i do left swipe in simulator, it is calling "didSwipeLeft" when control reaching [self.tabBarController setSelectedIndex:0] line, the function (didSwipeLeft) calling again. Please help me, how to resolve the problem, Is anyone have faced same problem. Thanks in Advance.

like image 997
sri Avatar asked Dec 03 '25 06:12

sri


1 Answers

I had this kind of problem with UIImagePickerController, and I solve it with an static int. Punt an static int or bool and reset it in view will appear and in in didSwipeLeft set it, and do the action only your static is not set. Hope that helps.

like image 117
Alex Terente Avatar answered Dec 05 '25 23:12

Alex Terente