'NSInternalInconsistencyException',原因:无法在包中加载NIB:'NSBundle

60

在我的AppDelegate中有一个我不理解的问题。RootViewController最初被称为ViewController,我改了它的名字。应用程序由许多ViewController组成,然后我引入了UINavigationController。为什么会出现这个错误?

  NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle 
  /Users/XXXXXXXXXXXX/Library/Application Support/iPhone simulator/6.0/Applications/
  B7A7D461-1CFE-4B05-AF32-00B65FCFFF49/XXXXXXXXXX.app> (loaded)'with name 
 'RootViewController''
  
  *** First throw call stack:
  (0x1992012 0x1357e7e 0x1991deb 0x4bafac 0x37fe37 0x380418 0x380648 0x380882 0
  x380b2a  0x397ef5 0x397fdb x398286 0x398381 0x398eab 0x398fc9 0x399055 0x49e3ab 
  0x2ef92d 0x136b6b0 0x1f12fc0 0x1f0733c 0x1f12eaf 0x38e8cd 0x2d71a6 0x2d5cbf 
  0x2d5bd9 0x2d4e34 0x2d4c6e 0x2d5a29 0x2d8922 0x382fec 0x2cfbc4 0x2cfdbf 
  0x2cff55 0x2d8f67 0x2b30 0x29c7b7 0x29cda7 0x29dfab 0x2af315 0x2b024b 0x2a1cf8 
  0x1dbedf9 0x1dbead0 0x1907bf5 0x1907962 0x1938bb6 0x1937f44 0x1937e1b 0x29d7da
  0x29f65c 0x269d 0x25c5) 
  ibc++abi.dylib: terminate called throwing an exception
  (lldb) 

这是在AppDelegate.h中的代码

  #import <UIKit/UIKit.h>

  @class RootViewController;

  @interface AppDelegate : UIResponder <UIApplicationDelegate>{

       UINavigationController *navigationController;
   }

  @property (strong, nonatomic) UIWindow *window;

  @property (strong, nonatomic) RootViewController *viewController;
  @property (strong, nonatomic) UINavigationController * navigationController;



  @end

这是AppDelegate.m的代码

  #import "AppDelegate.h"

  #import "RootViewController.h"



  @implementation AppDelegate

  @synthesize navigationController;
  @synthesize viewController;
  @synthesize window;



  - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:    (NSDictionary *)launchOptions
 {
         self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
        // Override point for customization after application launch.

         if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
               self.viewController = [[RootViewController alloc]      initWithNibName:@"RootViewController_iPhone.xib" bundle:nil];
   } else {
    self.viewController = [[RootViewController alloc] initWithNibName:@"RootViewController_iPad.xib" bundle:nil];
   }

    RootViewController *rootMenu=[[RootViewController alloc]initWithNibName:@"RootViewController" bundle:nil];

    self.navigationController =[[UINavigationController alloc]initWithRootViewController:rootMenu];

    self.window.rootViewController = self.navigationController;
    [self.window makeKeyAndVisible];
    return YES;
}

7
尝试从“Product-> Clean”清理您的项目,对我有用。 - uniruddh
重新运行项目对我有用。 - iYoung
我使用了强制语言功能,所以我改变了bundle。在更改语言后,我可以加载本地化的字符串和HTML文件。但是对于自定义的xib文件,我遇到了这个问题(“无法在bundle中加载NIB”)。请问我错过了什么? - Suresh Durishetti
对于故事板,这是我使用的方法 https://dev59.com/T2435IYBdhLWcg3wkBBe#56199366 - swiftBoy
清理和构建对我有用,谢谢! - Ethan Zhao
21个回答

0
解决方案对我有效: 1. 将.xib文件复制到桌面。 2. 通过Finder从项目中删除.xib文件。 3. 然后再次将我们在第一步中复制到桌面的.xib文件粘贴回去。 4. 现在从Finder将.xib文件拖放到Xcode文件夹中。 这样就可以正常工作了。
.xib文件的更改。
tableViewCell contentMode="scaleToFill" restorationIdentifier="<YOUR CELL NAME>" selectionStyle="default" indentationWidth="10" rowHeight="48" id="KGk-i7-Jjw" customClass="<YOUR CELL NAME>" customModule="Enphase" customModuleProvider="target"

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接