Xib not found after localization
Asked Answered
S

5

5

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...

Shakhty answered 16/4, 2013 at 18:22 Comment(1)
Show code when you call initWithNibName.Homothallic
O
25

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.

Obumbrate answered 20/5, 2013 at 3:48 Comment(5)
Same Problem with Xcode 4.6.3. Option Key + Clean, Reset Simulator, Curse, Quit Xcode, Relaunch Xcode, Build, Run -> Worked for me :DTonl
Deleting the app from the simulator, quitting Xcode, and manually deleting the derived data folder usually fixes this for me.Promoter
I was having a lot of trouble with this. My simulator doesn't crash but doesn't display the proper .xib (it clearly doesn't load). I did clear, delete app, restart Xcode, and works perfectly!Cryptomeria
I can't believe Apple releases XCode with so many obvious bugs like thisFagen
Quit Xcode, Relaunch Xcode, Build, Run -> Worked for me too!!Wolfe
O
1

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.

Oquinn answered 30/9, 2013 at 11:15 Comment(1)
I have tried this over and over, no fix. Restart Xcode didn't fix either. Using git, I reset all changes. But I really want to use base internationalization badly. Did you learn anything more on this?Hanger
H
0

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]
Homothallic answered 16/4, 2013 at 19:12 Comment(1)
This is how I'm initializing it: [[SPConfigViewController alloc] initWithNibName:@"SPConfigViewController" bundle:nil];Shakhty
M
0

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.

Mauceri answered 11/1, 2014 at 2:31 Comment(0)
U
0

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!

Unmentionable answered 25/10, 2018 at 10:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.