2012-01-26 9 views
0

私はiPhoneアプリケーションでビューを切り替えようとしていますが、ボタンをクリックして2番目のビューを表示すると、空白の画面が表示されます。ボタンとそれ以外のものが表示されます。ビューが正しく切り替わらない

私のストーリーボードファイルの2番目のViewControllerをチェックしました。そのカスタムクラスは、最初の2番目のViewControllerクラスを作成したときにすぐに削除された新しいインターフェイスファイルが付属していました。何が間違っているのでしょうか?

- (IBAction)Transition_NEXT:(id)sender 
{ 
     nextViewController = [[NextViewController alloc] 
           initWithNibName:@"NextViewController" 
           bundle:[NSBundle mainBundle]]; 
     [self presentModalViewController:nextViewController animated:NO]; 
} 
+0

ビューを切り替えるためのコードを投稿してください。 –

+0

- (IBAction)Transition_NEXT:(id)送信者 { nextViewController = [[NextViewController alloc] initWithNibName:@ "NextViewController" バンドル:[NSBundle mainBundle]]; [self presentModalViewController:nextViewController animated:NO]; } –

答えて

0

ストーリーボードを正しく使用しているとは思われません。ビューコントローラをインスタンス化する従来の方法であるので、initWithNibNameを使用するべきではありません。そのような新しいinstantiateViewControllerWithIdentifierを使用してみてください:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:[NSBundle mainBundle]]; 
UIViewController *nextView = [storyboard instantiateViewControllerWithIdentifier:@"NextViewController"]; 
[self.view presentModalViewController:nextView animated:YES]; 

すでにあなたのコントローラであなたのストーリーボードへの参照を持っている場合は、あなたが新しいものを初期化するべきではありませんが、代わりにあなたはちょうどあなたが持っている参照を使用する必要があります。

UIViewController *nextView = [self.storyboard instantiateViewControllerWithIdentifier:@"NextViewController"]; 
[self.view presentModalViewController:nextView animated:YES]; 
+0

よく機能します。どのように私は後戻り/機能を返すだろうか? –

+0

新しいビューの中から、 '[self dismissModalViewControllerAnimated:YES]; –

関連する問題