2012-12-11 108 views
0

下面的代码对我来说并不合适。每当该方法被称为应用程序崩溃我做错了什么?在UIViewController之间切换 - presentViewController

此代码使用故事板格式

在.h文件

@class SendVideoViewController; 

... 

@property (nonatomic) SendVideoViewController *sendVideoViewController; 

在.m文件

#import "SendVideoViewController.h" 
... 
@synthesize sendVideoViewController; 
... 
- (IBAction)signMeUpButtonPressed:(id)sender { 
termsAndConditionsViewController = [[TermsAndConditionsViewController alloc] init]; 
[self presentViewController:termsAndConditionsViewController animated:YES completion:nil]; 
//[self.view insertSubview:termsAndConditionsViewController.view atIndex:0]; 
} 
+0

如果我可以从这个网站得到一些固体的反馈只是一次就好。如果您发布答案,请回复该答案的评论。我不喜欢被告知只写什么,我也想知道这意味着什么 – nfoggia

回答

2

您的代码应阅读:

sendVideoViewController = [[SendVideoViewController alloc] init]; 
[self presentViewController:sendVideoViewController animated:YES completion:nil]; 

现在你是我实例化一个通用的UIViewController类。为了创建您在SendVideoViewController课程中定义的类型的对象,您需要在该课程上拨打+alloc,而不是UIViewController。你可能想要刷上the documentation

+0

感谢一吨。我很高兴你解释它。我在这里看到的大多数答案都是直接的代码。但谢谢你的帮助我了解 – nfoggia

+0

这段代码只会带来一个黑屏......我需要插入一个子视图到窗口吗? – nfoggia

+0

我按照方法使用了一个故事板 – nfoggia

0

试试这个:

sendVideoViewController = [[SendVideoViewController alloc] init]; 
[self presentViewController:sendVideoViewController animated:YES completion:nil]; 
+0

这不工作...我需要将视图添加到子视图吗? – nfoggia

+0

如果您正确地发布代码以便我们可以看到它,请将它做好。 – Kasaname

+0

这是所有必需的代码。 “视图切换器”代码处于无效方法,当故事板上的按钮被触摸时会被调用,但它会崩溃应用程序 – nfoggia