我正在尝试将Navigator Controller推送到另一个视图控制器,但我不断收到错误,说明无法加载nib包名称。这是我正在使用的代码:
SecondViewController *vc1 = [[SecondViewController alloc]
initWithNibName:NSStringFromClass([SecondViewController class]) bundle:Nil];
[self.navigationController pushViewController:vc1 animated:YES];
答案 0 :(得分: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];
修改强>
如果您正在使用Storyboard,则必须以不同方式加载GUI:
UIStoryboard *sboard = [UIStoryboard storyboardWithName:@"StoryboardFileName"
bundle:nil];
SecondViewController *vc1 = [sboard instantiateInitialViewController];