Could not load NIB in bundle :NSBundle - ios

I am trying to load a nib file from MainViewController but i get an exception which i mentioned below. I am not getting this exception regularly (1 out of fifty times). Check the exception below
Exception :
Could not load NIB in bundle: 'NSBundle </private/var/mobile/Containers/Bundle/Application/38ABE26C-F87E-49F1-9F29-E46E7ACDBD54/E2_IOS_App.app> (loaded)' with name 'NetWorkError'
the code i use to present this nib file is
NetWorkError *error=[[NetWorkError alloc]initWithNibName:#"NetWorkError" bundle:nil];
error.errorMessage=[details serverDownMessage]; // passing some message before presenting .
[self presentViewController:error animated:YES completion:nil];
i am using an iPad running with iOS 7.
People with similar issues where asked to check the nib name , check if the .xib is added to target, check if the .xib is added to copy bundle resource.But every thing is correct for me. what else might be the issue ??.

Have you tried NSStringFromClass([NetWorkError class]) ?
Also you can try to exclude and add file to your project again / clean project / delete app from simulator.

Related

Cannot load xib from framework

I can't seem to load a nib file in the framework I have created. The thing is I worked on it for more than a month and it was working fine. I opened it again today after 2 weeks and it's just crashing. I couldn't believe it.
I have created a tiny sample project where I am able to reproduce the issue.
To get the Bundle I am using
let bundle = Bundle(identifier: "com.nibFramework.NibFramework")
This is returning nil btw.
So I tried
let bundle = Bundle(for: MyNib.self)
Using the nib
let nib = UINib(nibName: "\(MyNib.self)", bundle: bundle)
let array = nib.instantiate(withOwner: self, options: nil)
And this is crashing on instantiate.
Error
2021-11-23 23:55:52.381944+0530 NibApp[7432:2147418] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle </private/var/containers/Bundle/Application/7817FD25-54BC-4920-AC67-49D246D28794/NibApp.app> (loaded)' with name 'MyNib''
*** First throw call stack:
(0x1827f904c 0x19ae6df54 0x182850180 0x18513f338 0x1040b0d9c 0x1040af164 0x1040af1c0 0x184db415c 0x184db6c10 0x184d896a4 0x184ecc4d8 0x184e21da0 0x184eb8f84 0x184ed3598 0x184c594a0 0x184f5f584 0x185260400 0x184f61c80 0x184ea10b4 0x1942f0e20 0x194316cdc 0x1942d16b4 0x1942d2cf4 0x10441e3b4 0x104421e70 0x1942d2f94 0x1942d23d4 0x1942d69e4 0x18281b020 0x18282bce0 0x182766054 0x18276b7f4 0x18277f3b8 0x19e10f38c 0x18511f6a8 0x184e9e7f4 0x199e98184 0x1040afcb8 0x1040afc40 0x1040afd38 0x104325a24)
libc++abi: terminating with uncaught exception of type NSException
dyld4 config: DYLD_LIBRARY_PATH=/usr/lib/system/introspection DYLD_INSERT_LIBRARIES=/Developer/usr/lib/libBacktraceRecording.dylib:/Developer/usr/lib/libMainThreadChecker.dylib:/Developer/Library/PrivateFrameworks/DTDDISupport.framework/libViewDebuggerSupport.dylib
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle </private/var/containers/Bundle/Application/7817FD25-54BC-4920-AC67-49D246D28794/NibApp.app> (loaded)' with name 'MyNib''
terminating with uncaught exception of type NSException
I am using Xcode 13.1. The Mach-O Type of this framework is set to Static Library.
Pretty sure I am missing some simple thing. Just can't figure out what. Thanks for your help.
Any Framework Bundle created with Xcodes Template will have a structure that you can rely on when looking for content packed in it.
Nib/Xib files are Resources, so with compiling they end up being copied into the according subfolder of the created Bundle (Framework in this case).
So you should be able to construct the needed Resources Folder manually.
NSString *privateFWPath = [[NSBundle mainBundle] privateFrameworksPath];
NSString *nibPath = [privateFWPath stringByAppendingString:#"/NibFramework.framework/Versions/A/Resources/MyNib"];
another way is to ask the class for its bundle and construct the frameworks Resources folder to reach the nib.
[NSBundle bundleForClass:MyNib.class];
PS: guessing MyNib.self is not a class, it is an object.
A way to check if the nib/xib ended up in the framework is to climb thru the folder structure with your desktops Finder.app. Your App will have a Frameworks folder, in there a NibFramework.framework and in this some link to Resources deeper into the structure or directly a Versions folder, subfolder A in which a Resources folder should be found and the nib will reside in. To do this you will compile first of course and then select the Product in your Xcode project, right click > show in Finder and then right click > Show Contents.
Hint: Asking Bundle for contents has a side effect when the input given results in (nil) or (null), it usually returns the mainBundle then.
Reminder: nib/xib/storyboard files do not reside in the root folder of a bundle.

Cannot find (secondary) storyboard named Test.storyboard

I would like to load a secondary storyboard Test.storyboard (next to Main.storyboard) in my app like so:
let storyboard = UIStoryboard(name: "Test.storyboard", bundle: nil)
Test.storyboard resides inside a group Test, it is marked for localization as Base (hence its Location Relative to Group is reported as Base.lproj/Test.storyboard) and it also marked for target membership in my app target. When I run the app on the simulator, I can confirm that a file Base.lproj/Test.storyboardc exists inside the app's main bundle.
Yet the above code produces this error:
Could not find a storyboard named 'Test.storyboard' in bundle ...
What is the right way to successfully package and load a secondary storyboard like mine?
You don't need to load storyboard with .storyboard extension .use like this
let storyboard = UIStoryboard(name: "Test", bundle: nil)

.xib file name is changed into ~iphone.nib while creating bundle

I am creating the framework, in that i have xib, images etc.. in frame work i am creating custom tableViewCell called SampleTableviewCell.xib. While this file is build into Bundle the name of the xib file is converted into SampleTableviewCell~iphone.nib. Because of this i am getting crash while loading this xib file in cellForRowAtIndexPath.
SampleTableviewCell *cell = (SampleTableviewCell *)[tableView dequeueReusableCellWithIdentifier:#"SampleTableviewCell"];
My crash is,
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle </Users/myname/Library/Developer/CoreSimulator/Devices/ACEB5838-EC42-416F-95AA-4CE5932D5849/data/Containers/Bundle/Application/B20C8F8B-5E09-4D84-960C-614185E955DE/myapp.app/MySDK.bundle> (not yet loaded)' with name 'SampleTableviewCell''
I dont know why it is hapening. Anyone please help me to fix this issue.Actually i dont want to have ~iphone in bundle.
Thanks.
After long struggle i found the solution,
In my xcode 7 beta 4 , changed the Deployment target of bundle from 6.0 to 8.0
This was protect me from creating nib file post fixed with ~iphone .
Try this
UINib *cellNib = [UINib nibWithNibName:#"SampleTableviewCell~iphone" bundle:nil];
[self.tableView registerNib:self.cellNib forCellReuseIdentifier:#"SampleTableviewCell"];
Hope it helps.

Added new target: Could not load NIB in bundle (NSInternalInconsistencyException)

I'm attempting to add a new build target in Xcode, and so far everything has been going fine - or I've at least been able to figure out why stuff was breaking/not compiling.
Now however, I'm stuck. When building and starting the app using the new target, the app fails with this:
* Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle (loaded)' with name 'Valider1''
* First throw call stack:
(0x2f71be83 0x39a7c6c7 0x2f71bdc5 0x321ff391 0x321610fb 0x31fc2b59 0x31ea479d 0x31f4f895 0x31f4f7ab 0x31f4ed89 0x31f4eab1 0x31f4e821 0x31f4e7b9 0x31ea0353 0x31b26943 0x31b22167 0x31b21ff9 0x31b21a0d 0x31b2181f 0x31f1fa3b 0x31f0aedf 0x31ea5a07 0x31ea4cfd 0x31f0a321 0x3438476d 0x34384357 0x2f6e6777 0x2f6e6713 0x2f6e4edf 0x2f64f471 0x2f64f253 0x31f095c3 0x31f04845 0xcd059 0x39f75ab7)
libc++abi.dylib: terminating with uncaught exception of type NSException
Now, I've searched for 2 hours regarding this, and theres a lot of results with suggestions, but none of them has solved the problem in my case.
The original build target works perfectly, and I'm using the same app delegate file for both targets.
Here's what I've tried so far:
Tried simulator/real device
Double checked that the "Valider1" is in "Compile sources"
Double checked that "Copy bundle resources" contains my "MainWindow.xib" (this is the nib used for "Valider1"
Double checked that "Valider1" is written correctly everywhere
Cleaned project 100 times
Validated that the Valider.m and "MainWindow.xib" has the new target checked in target membership
.plist files, build settings etc. is all identical to the original and working target
Please SO, tell me what I've done wrong or missed!
edit:
I call my nib like this:
Valider1 *validerVC = [[Valider1 alloc] initWithNibName:#"Valider1" bundle:nil mode:ny_mode];
validerVC.delegate = self;
and it works perfectly when using the original target.
EDIT 2:
I tried with another nib from my project, but still same error.
It would appear that the nibs are not being copied to the new target app, but I have no idea why :/
Remove and re-add the .xib file to Copy Bundle Resources
Go to your project settings.
Select your target.
Click on Build Phases.
Scroll down to Copy Bundle Resources and expand that section.
Check if your .xib file is present in this list -> then remove it.
Now re-add your .xib file by clicking the plus-button and find the file.
It helped me, I hope it helps you as well!

iPad specific resource suffix doesn't work with storyboards

According to the Apple's Resource Programming Guide you should be able to use device modifiers for any kind of resource file
Here's the quote
You can apply device modifiers to any type of resource file.
However while this seems to work for most resources (images, nibs) I'm running into problems when using it with storyboards.
What I've tried doing is having two storyboards with one of them having the ~ipad suffix attached to it's file name, and trying to load it like the following
UIStoryboard *mySB =
[UIStoryboard storyboardWithName:#"MyStoryboard" bundle:nil];
myViewController = [sigRequestSB instantiateInitialViewController];
And I'm getting a NSInternalInconsistencyException exception
The strange thing is that I only get this error if I have a storyboard with the ~ipad modifier, if I have only the single storyboard without the modifier it will just load that on the iPad. Further if I detect the what device is running and load the storyboard using the full file name (that is on an iPad attach the "~ipad" to the filename) it works.
Here's the full error
2013-08-29 15:32:44.294 MyApp[18757:c07] * Terminating app due to
uncaught exception 'NSInternalInconsistencyException', reason: 'Could
not load NIB in bundle: 'NSBundle
(loaded)' with name 'UIViewController-Cq1-k2-VhC' and directory
'MyStoryboard.storyboardc''

Resources