开发者

UISwipeGestureRecognizer called twice?

I'm having problem with UISwipeGestureRecognize calle开发者_StackOverflow中文版d 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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜