Search code examples
iphoneobjective-ciosuiswipegesturerecognizer

How to call gesture swipe method from another method in Objective-c


I have this gesture swipe method that I want to call from another method using

[self performSelector:@selector(handleSwipeGesture:) withObject:nil afterDelay:10];

I can't figure out the syntax to put in the @selector()

any help is appreciated. here's my code:

 - (IBAction)handleSwipeGesture:(UISwipeGestureRecognizer *)sender { 
        if(sender.direction == UISwipeGestureRecognizerDirectionLeft) {
            NSLog(@"swipe left");
            TutorialMenuViewController *tutorialMenuViewController = [[TutorialMenuViewController alloc]
                                                          initWithNibName:@"TutorialMenuViewController" bundle:nil];
            [self.navigationController pushViewController:tutorialMenuViewController animated:YES];
            [tutorialMenuViewController release];
        }
    }

Solution

  • If you want to present TutorialMenuViewController either on a gesture or time delay you would be better off just abstracting its presentation out into a different method

    - (IBAction)handleSwipeGesture:(UISwipeGestureRecognizer *)sender { 
        if(sender.direction == UISwipeGestureRecognizerDirectionLeft) {
            [self presentTutorial];
        }
    }
    
    - (void)presentTutorial;
    {
        TutorialMenuViewController *tutorialMenuViewController = [[TutorialMenuViewController alloc]
                                                          initWithNibName:@"TutorialMenuViewController" bundle:nil];
        [self.navigationController pushViewController:tutorialMenuViewController animated:YES];
        [tutorialMenuViewController release];
    }
    

    Now you can simply call

    [self performSelector:@selector(presentTutorial) withObject:nil afterDelay:10];