2012-11-01 64 views
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]; 

} 

但它崩潰輕掃。任何幫助?謝謝!

回答

0

您的代碼在我的Xcode上運行良好。 只有改變:

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

到:

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

,因爲我沒有UISecondViewController類。 只需驗證項目中是否存在UISecondViewController.xib,否則會崩潰。 但我不確定這是你的問題。

相關問題