0

ナビゲーター コントローラーを別のビュー コントローラーにプッシュしようとしていますが、nib バンドル名を読み込めないというエラーが表示され続けます。私が使用しているコードは次のとおりです。

SecondViewController *vc1 = [[SecondViewController alloc]
      initWithNibName:NSStringFromClass([SecondViewController class]) bundle:Nil];
[self.navigationController pushViewController:vc1 animated:YES];
4

1 に答える 1

1

クラス名ではなく、nib ファイルの名前を渡す必要があります。

// Assuming there is a properly set up SecondViewController.xib in your project.
SecondViewController *vc1 = [[SecondViewController alloc] 
                            initWithNibName:@"SecondViewController" bundle:nil];
[self.navigationController pushViewController:vc1 animated:YES];

編集:

ストーリーボードを使用している場合は、GUI を少し異なる方法でロードする必要があります。

UIStoryboard *sboard = [UIStoryboard storyboardWithName:@"StoryboardFileName" 
                                                 bundle:nil];
SecondViewController *vc1 = [sboard instantiateInitialViewController];
于 2012-09-16T00:03:49.753 に答える