2

我有一个基于选项卡的应用程序,我想使用滑动手势在视图控制器中导航。我试过:

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

}

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

4

1 回答 1

0

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

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

到:

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

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

于 2013-05-24T09:42:24.717 回答