1
votes

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];
        }
    }
2
you will have to register swipeGestureRecognizer for respective view.waheeda
thanks. what would be the syntax for the following? [self performSelector:@selector(handleSwipeGesture:) withObject:nil afterDelay:10];hanumanDev
What's the issue? You are calling it correctly although you will not get into the if statement as you are passing a nil object. So the if statement looks like this and evaluates to false [[nil direction] == UISwipeGestureRecognizerDirectionLeft]Paul.s

2 Answers

2
votes

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];
2
votes
- (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];
}
}

Called it like this:

 UISwipeGestureRecognizer *leftSwipe  =  [[UISwipeGestureRecognizer alloc] initWithTarget:nil action:nil];
[leftSwipe setDirection:(UISwipeGestureRecognizerDirectionLeft)];
[self performSelector:@selector(handleSwipeGesture:) withObject:leftSwipe afterDelay:1];
[leftSwipe release];