我正在尝试在iPhone应用程序中切换视图,但每当我点击按钮调出第二个视图时,我得到的只是一个空白屏幕,即使我已经用按钮和诸如此类的东西填充了视图。
我已经在我的storyboard文件中检查了第二个ViewController,它的自定义类是它需要的那个(当我最初创建第二个ViewController类时,它附带了一个新的接口文件,我立即将其删除)。我可能做错了什么?
- (IBAction)Transition_NEXT:(id)sender
{
nextViewController = [[NextViewController alloc]
initWithNibName:@"NextViewController"
bundle:[NSBundle mainBundle]];
[self presentModalViewController:nextViewController animated:NO];
}
答案 0 :(得分:0)
我认为你没有正确使用Storyboard。您不应该使用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];