【问题标题】:Nib Load Failed笔尖加载失败
【发布时间】:2013-08-16 10:25:22
【问题描述】:

在我的应用程序中,我制作了具有 5 个标签的自定义标签栏,每个标签显示不同的UIViewController

应用程序仅适用于 iPhone,所以我为每个 UIViewController 制作了 2 个 NIB(如果类名是 DayView,NIB 是 DayView_iPhone 和 DayView_iPhone5)。在设备和模拟器中,一切正常运行长达 10 分钟。

该应用程序崩溃后在控制台中显示:

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle </Users/kalyanasadinagarajugari/Library/Application Support/iPhone Simulator/6.1/Applications/0DEBB118-BA67-440F-BA70-79ED41AC9134/CalendarBlender.app> (loaded)' with name 'DayView_iPhone''

我还检查了 NIB 名称,每个 NIB 文件名都是正确的。

我的代码是

NSString *nibName = [AppDelegate fetchNibWithViewControllerName:@"DayView"]; 
dayView = [[DayView alloc] initWithNibName:nibName bundle:nil];

if (IS_IPHONE_5) 
    dayView.view.frame = CGRectMake(0, 44, 320, 463); 
else
    dayView.view.frame = CGRectMake(0, 44, 320, 375); dayView.view.tag=2; [self.view      
addSubview:dayView.view];

【问题讨论】:

标签: iphone ios objective-c xcode4


【解决方案1】:

尝试检查 Nibname(区分大小写)并清理项目,重新运行它。您是否更改了所有 nib 的类名?

【讨论】:

  • 每个 Nibname 都是完美的,我检查了所有的 nibname。我的问题会在不断更改标签后出现。
  • NSString *nibName = [AppDelegate fetchNibWithViewControllerName:@"DayView"]; dayView = [[DayView alloc] initWithNibName:nibName bundle:nil]; if (IS_IPHONE_5) dayView.view.frame = CGRectMake(0, 44, 320, 463);否则 dayView.view.frame = CGRectMake(0, 44, 320, 375); dayView.view.tag=2; [self.view addSubview:dayView.view];
  • 这就是我的调用方式,代码有问题吗,笔尖名称分别是 DayView_iPhone、DayView_iPhone5
  • 在您的问题中添加您的代码..以便我们清楚地理解它。
  • 这段代码你是在哪里写的?即在 DidfinishLaunchingwithoptions 中还是在哪里?
【解决方案2】:

使用这个:

- (void)applicationDidFinishLaunching:(UIApplication *)application {
   tabBarController = [[UITabBarController alloc] init];

   MyViewController* vc1 = [[MyViewController alloc] initWithNibName:@"nibName" bundle:nil];
   MyOtherViewController* vc2 = [[MyOtherViewController alloc] initWithNibName:@"nibName" bundle:nil];

   NSArray* controllers = [NSArray arrayWithObjects:vc1, vc2, nil];
   tabBarController.viewControllers = controllers;

    window.rootViewController = tabBarController;
}

您也可以通过在 tabBarController 的 viewControllers 数组中添加控制器来动态添加控制器。

【讨论】: