5
votes

I've added a new localization for italian language in my project and after that I localized a xib file to start the translation of the project. The problem is, now when I run my project in the simulator, none of the xibs are found.

(GAIUncaughtExceptionHandler.m:41): Uncaught exception: Could not load NIB in bundle: 'NSBundle ...

I'm instantiating the file owner of this xib using initWithNibName.

I've tried both pure localization of the xib and the base localization, but none of them are working.

I'm initializing the owner like this:

[[SPConfigViewController alloc] initWithNibName:@"SPConfigViewController" bundle:nil];

EDIT:

After I created the localized version of the xib, I decided to just close XCode and open it again, and it worked...

5
Show code when you call initWithNibName.Vitaly Berg

5 Answers

25
votes

I had the same experience and what a mind trip...

Process:

(Assumes a project that has chosen "Use Base Internationalization" in the Project's Info)

  1. Click on a .xib resource in the File Navigator, which loads Interface Builder
  2. Using the File Inspector, click the Localize button
  3. A modal presents asking which language you would like to use ("Base" was unavailable to me, so I picked "English")
  4. Now in the Localized section of the File Inspector a checkmark is next to English and none next to Base, so I checked Base
  5. Then I was given a picker for how I wanted English to be localized: Interface Builder Cocoa Touch XIB or Localizable Strings

Okay, I was optimistic that this would work, so run...
... and crash

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle < /var/mobile/Applications/_____/_____.app> (loaded)' with name '__MY NIB STRING HERE___''

Clean, Build, Run -> Crash
Option Key + Clean, Build, Run -> Crash
Option Key + Clean, Delete App, Build, Run -> Crash
Option Key + Clean, Reset Simulator, Curse, Build, Run -> Crash

Quit Xcode, Relaunch Xcode, Build, Run -> Works! WTF.

I've opened a Bug Report against the issues and would appreciate if you run into this problem that you would duplicate it so the developer tools team knows its a reoccurring issue.

1
votes

This seems to be caused by the fact that localising a xib file moves it to a new directory (base.lproj) inside your projects root directory, after which xcode can no longer find the xib file.

I resolved this by going to the project file, selecting my target, going to the build phase tab. Then if you expand the 'Copy Bundle Resources' folder you should notice that the file that was being complained about in the NSException is coloured red. I removed this file and readded the localised version found in the 'base.lproj' sub folder and this seemed to fix the issue.

As far as I am aware this would need to be done for every localised xib, which is a ton of unecessary faffing around (thanks xcode...) but hey, the app no longer crashes.

0
votes

You could do so:

[[YourViewController alloc] initWithNibName:@"YouViewController.xib" bundle:nil]

Don't use extension for view controller's nib name, try as bellow:

[[YourViewController alloc] initWithNibName:@"YouViewController" bundle:nil]
0
votes

Verify that you have the file localized for all languages. I had left English unchecked and it would fail in this way. I couldn't get it to show up correctly in 'Copy Bundle Resources' until I checked English and then re-added the cob. You can tell it is ok because it won't be in red and it will say '... in/MyProject/(localization).lproj', where MyProject will, of course, be the name of your project.

0
votes

In my case I renamed one of the localization folders from Base.lproj to base.lproj. After renaming it back and replacing all occurrences on base to Base in .pbxproj it works!