0

我正在尝试将 Navigator Controller 推送到另一个视图控制器,但我不断收到错误消息,提示无法加载 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];

编辑:

如果你使用 Storyboards,你必须以不同的方式加载你的 GUI:

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