为什么xcode无法加载我的NIB

时间:2014-11-12 02:56:41

标签: ios objective-c xcode

在XCode中运行程序时,我收到以下错误:

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle </Users/user/Library/Developer/CoreSimulator/Devices/646F9805-AC4E-40A8-BC62-75B92339DCDC/data/Containers/Bundle/Application/D6C27367-F61B-4CAC-BB9E-1D48227CE629/WhatsNap.app> (loaded)' with name 'DisplayWarningViewController''

我正在运行以下代码行,并在最后一行获得异常。我不确定为什么会这样。 SO上关于这个主题的其他答案表明nib文件可能没有连接?

DisplayWarningViewController* DWVC = [[DisplayWarningViewController alloc]initWithNibName:@"DisplayWarningViewController" bundle:nil];
DWVC.delegate = self;
[self presentViewController:DWVC animated:NO completion:nil];

1 个答案:

答案 0 :(得分:1)

看起来你在故事板中定义了视图控制器!在那种情况下你应该做

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];

DisplayWarningViewController *displayWarningVC = (DisplayWarningViewController *)[storyboard instantiateViewControllerWithIdentifier:@"DisplayWarningViewController"]