137

I am trying to integrate Janrain Engage as custom module with Appcelerator Titanium. I have created a sample module and dragged the JREngage folder to the sample module xcodeproj as indicated in the Jainrain's documentation.

Now I give build command to this project, then execute the ./build.py and then finally I execute the titanium run command. It launches the application in simulator with a blank screen and immediately crashes throwing the following error.

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle </Users/abhilash/Library/Application Support/iPhone Simulator/4.2/Applications/CA167346-4091-4E16-B841-955D1D391713/test.app> (loaded)' with name 'JRProvidersController''

Why could this error be occurring?

swiftBoy
  • 35,607
  • 26
  • 136
  • 135
Goje87
  • 2,839
  • 7
  • 28
  • 48

34 Answers34

247

Visit the properties of the .xib files in the file inspector,the property "Target Membership" pitch on the select box, then your xib file was linked with your target

ScottyBlades
  • 12,189
  • 5
  • 77
  • 85
sevenpounds
  • 2,471
  • 1
  • 13
  • 5
90

In Targets -> Build Phases

Make sure the .xib is added to Copy Bundle Resources, if it is not present then add .xib file.

Bruno Bieri
  • 9,724
  • 11
  • 63
  • 92
kunalg
  • 1,570
  • 1
  • 12
  • 18
23

try to find out all

XXXController = [[XXXControlloer alloc] initWithNibName:@"XXXController" bundle:nil];

in your code, and make sure that XXXController are spelled correctly

Guillaume Algis
  • 10,705
  • 6
  • 44
  • 72
chings228
  • 1,859
  • 24
  • 24
15

I had the same problem (exception 'Could not load NIB in bundle: ..') after upgrading my xcode from 3.2 to 4.02. Whereas deploying of my app with Xcode 3.2 worked fine it crashes with xcode 4 raising the exception mentioned above - but only when I tried to deploy to the IOS Simulator (v.4.2). Targeting the IOS device (v.4.1) acted also with Xcode 4.

It turned out (after hours of desperately scrabbling around) that the reason was an almost "hidden" setting in the .xib-file:

Visit the properties of the .xib files in the file inspector: The property 'Location' was set to 'Relative to Group' for all .xib files. I changed it to 'Relative to project' and voila: all .xib files now are correctly loaded in IOS simulator !

I have no clue what's the reason behind that for this odd Xcode4 behavior but maybe it's worth to make an attempt ?

creator_11
  • 701
  • 1
  • 7
  • 12
14

In my case it was very weird (use a storyboard): For some reason it changed from "Main storyboard file base name" to "Main nib file base name" in the plist.

Changing back to "Main storyboard file base name" (UIMainStoryboardFile) solved the issue

Tibidabo
  • 21,461
  • 5
  • 90
  • 86
  • 1
    This solved my problem! Thank you. I had just duplicated my project and renamed all the pertinent files. Everything worked but this. Now everything works!! – BeccaP Sep 18 '14 at 23:57
13

the error means that there is no .xib file with "JRProvidersController" name. recheck whether JRProvidersController.xib exists.

you will load .xib file with

controller = [[JRProvidersController alloc] initWithNibName:@"JRProvidersController" bundle:nil];
Kundan
  • 3,084
  • 2
  • 28
  • 65
Hanuman
  • 642
  • 5
  • 19
  • 1
    Hey Hanuman, I have checked that file JRProvidersController.xib exists. I have also tried to rename the file and execute, even then it's throwing the same exception. – Goje87 Mar 17 '11 at 11:51
  • try changing the invocation to initWithNibName:NSStringFromClass([MyViewController class]). Also check closely for file name as it is case sensitive – Hanuman Mar 18 '11 at 08:14
  • http://stackoverflow.com/questions/4155292/could-not-load-nib-in-bundle-on-iphone-device – Hanuman Mar 18 '11 at 08:14
  • I have made the changes suggested by you, but have got no success. – Goje87 Mar 29 '11 at 06:04
8

I had this problem with a storyboard and the nib was called something like 'bKD-J3-fhr-view-ZSR-8m-2da'.

It was because I was trying to add a subview to self.view in a view controller's init (withCoder). Self.view doesn't exist yet.

Moved it to viewDidLoad and all better!

Will Larche
  • 3,119
  • 7
  • 26
  • 34
  • 1
    Similarly, I got an error like this when I (foolishly) tried to assign a table view delegate and data source in the init() rather than viewDidLoad() – jpb Aug 17 '20 at 03:32
  • I did the exact thing, mistakenly imagined some deep NIB build/update issue when it was just this very premature delegate assignment in init – John Gorenfeld Apr 27 '23 at 12:07
8

Using a custom Swift view in an Objective-C view controller (yes, even after importing the <<PROJECT NAME>>-Swift.h file), I'd tried to load the nib using:

MyCustomView *customView = [[[NSBundle mainBundle] loadNibNamed:NSStringFromClass([MyCustomView class]) owner:self options:nil] objectAtIndex:0];

...but NSStringFromClass([MyCustomView class]) returns <<PROJECT NAME>>.MyCustomViewand the load fails. TL;DR All worked well loading the nib using a string literal:

MyCustomView *customView = [[[NSBundle mainBundle] loadNibNamed:@"MyCustomView" owner:self options:nil] objectAtIndex:0];
shim
  • 9,289
  • 12
  • 69
  • 108
Tom Howard
  • 4,672
  • 2
  • 43
  • 48
7

Have look at the project

Target -> Build Phases -> Copy Bundle Resources

You will find your xib/storyborad with red color.

Just remove it.Also remove all references of missing file from project.

Now drag this storyboard/xib file again to this Copy Bundle Resources.It will still show you file with red color but dont worry about it.

Just clean and build project.

Now you will get your project running again successfully!!

Gonzalo.-
  • 12,512
  • 5
  • 50
  • 82
Chirag Lukhi
  • 1,528
  • 17
  • 41
  • 1
    This solved my problem, since I got two storyboards "MyStoryboard.storyboard" and "MyStoryboard~ipad.storyboad"...so from the iPad target I removed "MyStoryboard.storyboard" from the "Copy Bundle Resources" – i89 Dec 16 '15 at 16:41
7

DO NOT PUT .xib WHEN YOU INSERT IN THE XIB NAME! IT IS ALREADY IMPLIED!

Dont do this:

 UIView *viewFromNib = [[NSBundle mainBundle] loadNibNamed:@"ResultsAssessmentView.xib" owner:self options:nil][0];

Do this:

 UIView *viewFromNib = [[NSBundle mainBundle] loadNibNamed:@"ResultsAssessmentView" owner:self options:nil][0];
coolcool1994
  • 3,704
  • 4
  • 39
  • 43
6

For Storyboard

I tried every single solution posted here but nothing worked for me as I am using Storyboard with Swift 5.

Just started to build fresh controllers and Views in storyboard test app, what I found is I was missing My View Controller's Storyboard ID.

So here is my solution, If you want to Go from ViewController A --> View Controller B

Step 1. In storyboard : Just make sure your ViewControllerA is embedded in Navigation Controller

Step 2. In storyboard : Now check have you mentioned Storyboard ID for your ViewControllerB which you will use in code as Identifier.

enter image description here

Step 3. and finally make sure you are pushing controller this way in your ViewControllerA with Button click.

if let viewControllerB = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "ViewControllerB") as? ViewControllerB {

            if let navigator = navigationController {
                navigator.pushViewController(viewControllerB, animated: true)
            }
        }
swiftBoy
  • 35,607
  • 26
  • 136
  • 135
6

With the build target being one of my iOS devices, I right-clicked the Product file (xyzw.app) and selected the Show in Finder popup item. It opened a window with the xyzw.app inside; I opened the bundle using Show Package Contents and saw all the files I expected, except one file, the one it was complaining about, with a capital I instead of a lower-case i in the name (zoomieVIew.nib instead of zoomieView.nib). I had noticed the uppercase I in the file name of the xib, and changed it and rebuilt; apparently Xcode left the generated .nib name the way it was. I deleted zoomieVIew.nib in the bundle, rebuilt, and Xcode duly recreated the file as zoomieView.nib. The app started to work on the device.

  • same thing here as michael is describing. i had created a xib file holding a custom UITableViewCell. when i open the .app and searched for myCell.xib, i see it's actually myCell.nib. further more, the app was only crashing on the device and load the xib file okay when executing on the simulator. it was a bit tricky to reset it. for me at least. only when i deleted the file, cleaned the target and copied the file back - did it work. – Nir Pengas Apr 29 '12 at 01:39
  • marked up as it also shows an easy way to find and view the package contents – fotisgpap Jan 17 '15 at 11:46
  • doh. how could I get myself to this again. thanks kind man:) i was at very beginning of the researching this problem – heximal Feb 16 '19 at 22:06
5

It happens when you rename the nib file. If you have already, create new nib(meaning copy current nib file contents to new nib), delete old nib file and it will solve your problem.

Edit: With new Xcode starting version 4.6.3, If you rename(with refactor feature) Controller class, it will rename nib file too and you need not worry about nib loading problem.

NetDeveloper
  • 509
  • 1
  • 9
  • 20
5

Swift4 example if your MyCustomView.swift and MyCustomView.xib in a framework. Place this in the MyCustomView's init:

let bundle = Bundle(for: type(of: self))
let nib = UINib(nibName: "MyCustomView", bundle: bundle)
if let nibView = nib.instantiate(withOwner: self, options: nil).first as? UIView {
    self.aViewInMyCustomView = nibView
    self.aViewInMyCustomView.frame = self.frame
    self.addSubview(self.aViewInMyCustomView)
    // set constraints
    self.translatesAutoresizingMaskIntoConstraints = false
    NSLayoutConstraint(item: self.aViewInMyCustomView, attribute: .leading, relatedBy: .equal, toItem: self, attribute: .leading, multiplier: 1.0, constant: 0).isActive = true
    NSLayoutConstraint(item: self.aViewInMyCustomView, attribute: .trailing, relatedBy: .equal, toItem: self, attribute: .trailing, multiplier: 1.0, constant: 0).isActive = true
    NSLayoutConstraint(item: self.aViewInMyCustomView, attribute: .top, relatedBy: .equal, toItem: self, attribute: .top, multiplier: 1.0, constant: 0).isActive = true
    NSLayoutConstraint(item: self.aViewInMyCustomView, attribute: .bottom, relatedBy: .equal, toItem: self, attribute: .bottom, multiplier: 1.0, constant: 0).isActive = true
} 
norbDEV
  • 4,795
  • 2
  • 37
  • 28
4

Be careful: Xcode is caseSensitive with file names. It's not the same "Fun" than "fun".

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
oskarko
  • 3,382
  • 1
  • 26
  • 26
  • 1
    File name for my nib was FormItemCheckBoxCell.nib, class was FormItemCheckboxCell. Capitalizing "Box" in the name cost 45 minutes of my life. – SafeFastExpressive Apr 09 '20 at 21:16
3

I also found that it failed when I tried to load the XIB with a name like @"MyFile.xib". When I just used @"MyFile" it worked - apparently it always adds the extension. But the error message just said it couldn't find MyFIle.xib in the bundle - if it had said MyFile.xib.xib, that would have been a big clue.

Jonathan Starr
  • 236
  • 4
  • 15
  • The reason you mustn't add the extension is that in your compiled bundle, .xib files are also compiled into .nib files. So there actually wasn't a MyFile.xib in your bundle, nevermind the double extension. – Pieter Jongsma Jul 22 '13 at 22:59
3

Your XIB file is probably outside your project folder. This leads to not showing up the Target Inspector. However, moving the XIB file into your project folder should fix it.

hhamm
  • 1,511
  • 15
  • 22
2

Working on Xcode 4.6.3 and localizing my NIB files I also run into this issue.

For me nothing else helped besides changing "Document Versioning" in File Inspector to Deployment 5.0 instead of 6.1.

krafter
  • 1,425
  • 1
  • 15
  • 28
2

I just had an interesting experience using Xcode 6.3.

I kept getting this error also, despite trying everything you would normally think of with spelling, target membership, etc. as suggested above. I also tried cleaning, deleting derived data, and also deleting the app from the simulator several times to ensure the bundle was being built correctly but to no avail.

Finally, following Brian Michael Bentley's answer, I finally decided to inspect my .app file in my simulator's folder on my HD. I found that all of my nibs were there but with a abc~ipad.nib instead of the expected abc.nib. I manually renamed all of these files to remove the ~ipad part, built and it worked!

Trying to see why these have been appended with the ~ipad keyword, I looked at my project settings and in fact, in my General>Deployment Info tab, I had only iPad selected. I was trying to run on an iPhone simulator. I believe that in the past, Xcode would give an error indicating that the binary did not support iPhone and you would not succeed in running the app.

I deleted the app from the simulator and did the same thing again - again with only iPad supported. This time, the .app contained abc~iphone.nib AND abc~ipad.nib for each expected storyboard and it ran on the iPhone simulator just fine. Again - If we choose iPad only in our Deployment Info settings, it shouldn't run on iPhone Simulator. This is an Xcode bug.

So, there is some inconsistent behavior here on the part of Xcode and unfortunately it's an intermittent bug and this may be difficult to reproduce, but I put this here so that it may help others in the future.

2

Had this same issue nothing worked, so I figured something weird with derived data.

In xcode 6.3.2 I had to:

In XCode Menu --> Preferences --> Locations Tab --> In Locations Change Derived Data to Relative and then toggle back to Default

Then the nib loaded fine.

Kevin
  • 1,883
  • 16
  • 23
  • I just deleted Derived Data folder and it worked. Seems to get confused because I had renamed the xib file in the project navigation. Odd one. – Kyle Goslan Jul 27 '16 at 17:47
2

for me, it solved just by changing the name of my cell's file into the same as its class.

In Attributes Inspector(Third tab on the right side bar in story board):

  1. Set the cell's Identifier( for example: "MyCellId"),
  2. Set the cell's Class (for example: "MyCellClass" when the file is "MyCellClass") ,
  3. Register the cell in your view controller as follow:

    tableView.register(UINib(nibName: "MyCellClass", bundle: nil), forCellReuseIdentifier: "MyCellId")

Marjan Basiri
  • 184
  • 1
  • 10
1

In case you are using frameworks in your project, you need to make sure you are loading from the correct bundle:

NSBundle *bundle = [NSBundle bundleWithIdentifier:@"<your bundle id here>"];
ABCViewController *vc = [[ABCViewController alloc] initWithNibName:@"<your nib name>" bundle:bundle];
david72
  • 7,151
  • 3
  • 37
  • 59
1

I've got same issue and my .xib file has already linked in Target Membership with the Project. Then I unchecked the file's target checkbox and checked again, then Clean and Build the project. Interestingly it has worked for me.

eemrah
  • 1,603
  • 3
  • 19
  • 37
1

In my case the spellings of XIB was incorrect. Please make sure the spellings are correct. Bundle.main.loadNibName("XIB_Name" , owner : self , options :nil)

Muhammad Essa
  • 219
  • 2
  • 6
1

I ran into the same problem. In my case the nib name was "MyViewController.xib" and I renamed it to "MyView.xib". This got rid of the error.

I was also moving a project from XCode 3 to 4.2. Changing the Path type did not matter.

vesselhead
  • 331
  • 4
  • 13
  • I had an extra character in my .xib file name. If I didn't come across your answer, I might have never figured it out. Thanks a lot. – Pravalika Sep 17 '20 at 14:52
0

Every time I refactor a view controller's name that's in my appDelegate I waste time on this. Refactoring doesn't change the nib name in initWithNibName:@"MYOldViewControllerName".

cloudsurfin
  • 2,467
  • 2
  • 25
  • 29
0

I had same problem, renaming my view controller identifier in storyboard worked for me.

Dave
  • 4,376
  • 3
  • 24
  • 37
0

I noticed that it may happen if you switch between branches in git and forget to make a clean. So xib is there and everything is find, but the exact build may have problems. So just in case don't forget to make a clean

Ezeki
  • 1,519
  • 10
  • 17
0
SecondViewController *secondViewController = [[SecondViewController alloc]initWithNibName:@"SecondView.xib" bundle:nil];
    [self.navigationController pushViewController:secondViewController animated:YES];

In the above code, if you also give a file extension like "SecondView.xib", then it's wrong and will give you above error. Use "SecondView" instead. I have made that mistake.

NSPratik
  • 4,714
  • 7
  • 51
  • 81
0

This is worked for me.. Make sure you typed nib name correctly.

[[NSBundle mainBundle]loadNibNamed:@"Graphview" owner:self options:nil];

Graphview(nib name)

Narasimha Nallamsetty
  • 1,215
  • 14
  • 16
0

For me, the case was that I was searching the main bundle for a nib which wasn't in the main bundle. My nib was in an imported module so I needed to retrieve the bundle for that module and use it to init the UINib, rather than using Bundle.main.

Oletha
  • 7,324
  • 1
  • 26
  • 46
0

In my case, I was creating a framework with Cocoapods. The problems was this line:

s.static_framework = true

in my framework.podspec file

After commented this line above all problems to access storyboards or XIBs went out.

Ronaldo Albertini
  • 1,329
  • 20
  • 24
0

Got this problem while transforming my old code from XCode 3x to XCode 4 and Solved it by just renaming wwwwwwww.xib into RootViewController.xib

Nikolay Frick
  • 2,145
  • 22
  • 17
0

Also the reason can be the file is looked up in the wrong language specific folder when you messed with localizations.

MacMark
  • 6,239
  • 2
  • 36
  • 41