如何使用滑动手势加载第二个视图控制器?

时间:2012-11-01 14:17:32

标签: uiviewcontroller uigesturerecognizer

我有一个基于标签的应用程序,我想使用滑动手势来浏览视图控制器。 我试过了:

    - (IBAction)swipeLeftDetected:(UIGestureRecognizer *)sender {
UISecondViewController *second =[[UISecondViewController alloc] initWithNibName:@"UISecondViewController" bundle:nil];
second.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:second animated:YES];

} 

与此配对:

    - (void)viewDidLoad; {
UISwipeGestureRecognizer *swipeRecognizer = [[UISwipeGestureRecognizer alloc]    initWithTarget:self action:@selector(swipeLeftDetected:)];
swipeRecognizer.direction = UISwipeGestureRecognizerDirectionLeft;
[self.view addGestureRecognizer:swipeRecognizer];

}

但它在滑动时崩溃了。有帮助吗?谢谢!

1 个答案:

答案 0 :(得分:0)

您的代码在我的Xcode上运行良好。 只是改变了:

UISecondViewController *second =[[UISecondViewController alloc] initWithNibName:@"UISecondViewController" bundle:nil];

为:

SecondViewController *second =[[SecondViewController alloc] init];

因为我没有UISecondViewController类。 只需验证项目中是否存在UISecondViewController.xib,否则会崩溃。 但我不确定这是你的问题。