2012-12-11 107 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