无法推送到XIB iOS

问题描述:

在我的应用中,我尝试使用long tap事件推送到XIB。我做了下面的代码,无法推送到XIB iOS

在viewDidLoad中

UILongPressGestureRecognizer *longPress = [[[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPress:)]autorelease]; 
longPress.delegate = (id<UIGestureRecognizerDelegate>)self; 
[self.view addGestureRecognizer:longPress]; 
[longPress requireGestureRecognizerToFail:doubleTap]; 

长按的方法是

- (void)longPress:(UILongPressGestureRecognizer*)gesture { 
if (gesture.state == UIGestureRecognizerStateEnded) { 
ProductDetailViewController *vc = [[[ProductDetailViewController alloc] initWithNibName:@"ProductDetailViewController" bundle:nil] autorelease]; 
[self.navigationController pushViewController:vc animated:YES]; 
    NSLog(@"Long Press"); 
} 

} 我有一个XIB名为ProductDetails.xib,我设置它的File's Owner作为ProductDetailViewController

当我运行此代码NSLog正在工作。但它不会去ProductDetails.h。也没有错误。我怎样才能解决这个问题?任何人都可以帮助我。

在此先感谢!

您已经将xib连接到控制器,您可以通过以下操作实现此目的。

ProductDetailViewController *vc = [[[ProductDetailViewController alloc] init] autorelease]; 
[self.navigationController pushViewController:vc animated:YES]; 
+0

它不工作。 – codebot 2014-10-26 14:42:10

+0

是否有可能navigationController是零?如果没有,尝试删除ProductDetailViewController并重新添加它,当您添加它时,包含xib文件。 – gabbler 2014-10-26 14:45:51

+0

导航控制器为零。 – codebot 2014-10-26 14:54:18