1

我有这个手势滑动方法,我想从另一个方法调用

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

我无法弄清楚要放入@selector()的语法

任何帮助表示赞赏。这是我的代码:

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

2 回答 2

2

如果您想以TutorialMenuViewController手势或时间延迟呈现,最好将其呈现抽象为不同的方法

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

现在您可以简单地调用

[self performSelector:@selector(presentTutorial) withObject:nil afterDelay:10];
于 2012-05-21T10:22:07.507 回答
2
- (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];
}
}

像这样称呼它:

 UISwipeGestureRecognizer *leftSwipe  =  [[UISwipeGestureRecognizer alloc] initWithTarget:nil action:nil];
[leftSwipe setDirection:(UISwipeGestureRecognizerDirectionLeft)];
[self performSelector:@selector(handleSwipeGesture:) withObject:leftSwipe afterDelay:1];
[leftSwipe release];
于 2012-05-21T10:25:38.720 回答