Could not load NIB in bundle ImageViewCell - objective-c

I'm getting this error while running simulator. The project was not created on this environment, not sure I'm missing a configuration setting.
Error
2012-08-08 19:30:56.411 ACME[4068:f803] mItemArray.count: 2 2012-08-08 19:30:56.413 ACME[4068:f803] * Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle (loaded)' with name 'ImageViewCell''
if(cell == nil)
{
NSArray *array = [[NSBundle mainBundle] loadNibNamed:#"ImageViewCell" owner:self options:nil];
cell = [array objectAtIndex:0];
}

You have not set the "files owner" in the NIB file to the owner you are setting in code. The NIB loader will fail like this when it cant link the objects in the NIB to the right root owner.

The name after "loadNibNamed:" must be the name of the nib file (in project navigator on the left side of the screen), sometimes people write there 'cell identifier' that writes from the start in CellForRowAtIndexPath (static NSString ...).
May be your problem in this little fault?

Related

What does internalconsistency mean?

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle </var/mobile/Applications/C8CF9D6E-4B29-416B-8973-A6F18C0CE691/.app> (loaded)' with name 'BGCinemaScheduleCell''
*** First throw call stack:
(0x32d812a3 0x3aa2697f 0x32d811c5 0x34d26571 0x34d2e2b7 0x137e4d 0x13833f 0x1383fd 0x1b6b97 0x34dffdef 0x17218b 0x34bd454d 0x34bb9313 0x34bd07cf 0x34b8c803 0x34936d8b 0x34936929 0x3493785d 0x34937243 0x34937051 0x34936eb1 0x32d566cd 0x32d549c1 0x32d54d17 0x32cc7ebd 0x32cc7d49 0x3688b2eb 0x34bdd301 0xa1385 0x3ae5db20)
libc++abi.dylib: terminate called throwing an exception
Okay there is indeed an actual XIB named BGCinemaScheduleCell
I got this error here:
-(void) vLoadMainBundle
{
if ([self class] == [BGBaseTableViewCell class])
{
return;
}
NSString * className = NSStringFromClass([self class]);
[[NSBundle mainBundle] loadNibNamed:className owner:self options:nil];
}
I have no idea what NSInternalInconsistencyException mean. the value of className is loadNibNamed
It turns out the xib hasn't been copied to the bundle resources that an answer in https://stackoverflow.com/a/5646337/2027232 would work.
The next question would be why the xib isn't copied to the bundle resources when I created it.

Loading nib from my own bundle?

i'm trying to put NIB/XIB files in a bundle I call Configuration.bundle. When I try to load the xib from my bundle the app crashes because it can't find the xib file.
NSBundle *bundle = [NSBundle bundleWithPath:[[NSBundle mainBundle]
pathForResource:#"Configuration" ofType:#"bundle"]];
[bundle load];
NSLog(#"bundle: %#", bundle);
I get the output
bundle: NSBundle (not yet loaded)
The 'not yet loaded' part scares me a bit. Why isn't it loaded?
And finally when I try to load my nib with the view controller
ConfigViewController *configViewController = [[ConfigViewController alloc] initWithNibName:#"ConfigViewController" bundle:bundle];
I get the output
* Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle (not yet loaded)' with name 'ConfigViewController.xib'
I've tried both with and without .xib.
Any ideas?
The load method is used to load executable code like frameworks and these things.
Your bundle doesn't contain any executable file that you want to load, so you don't neel to call [bundle load].
If the name of the bundle ir right, then all you've written except for [bundle load] is fine.Anyways check that the path is the right ones, don't nest too much the instructions:
NSString* path=[ [NSBundle mainBundle] pathForResource: #"Configuration" ofType: #"bundle"];
If this string is the right path, then you are sure that the bundle will be loaded correctly without calling [bundle load].
First of all if a bundle is not created properly it will not get loaded. So in-order to create a proper bundle below are the steps for creating a bundle:
1. Add a new target by choosing a templete named bundle under OS X -> Framework & Libraries.
Select newly created target and change BaseSDK from OSX to Latest iOS.
Add .xibs, images or other resources which you want to use it from bundle in Build Phrases -> Copy Bundle Resources.
Add CoreFoundation framework in Build Phrases -> Link binary with Libraries.
Compile the target choosing iOS Device.
Save the newly created bundle from Products directory to some place.
Now copy that bundle into your main project. Load a bundle using below code:
NSString *path = [[NSBundle mainBundle] pathForResource:#"BundleName" ofType:#"bundle"];
NSBundle *bundle = [NSBundle bundleWithPath:path];"
You are now set with the new bundle.

Error implementing UIWebView to load local html

am trying to add a UIWebView to my current UIScrollView. The UIWebView is supposed to access a local html file 'index.html'. I got an error at runtime:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSURL initFileURLWithPath:]: nil string parameter'
This is my code:
UIWebView *webView = [[UIWebView alloc] initWithFrame:scrollViewFrame];
NSString *indexPath = [NSBundle pathForResource:#"index" ofType:#"html" inDirectory:#"Addition"];
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:indexPath]]];
I do have 'Addition' folder (not group; imported from 'Add' in my project).
Thanx in advance...
Did you check indexPath with a breakpoint or NSLog? It looks like your file is not there (perhaps a typo?)-
EDIT
OK, I just tested this successfully. Try this:
Delete all the web files from your project.
Copy the web directory into the right place in your project folder.
Drag from Finder to Xcode, do not copy, Create folder references
One more caveat: Maybe there is a difference in capitalized resource names between the simulator and the device. Try using lowercase throughout.
Also, you should perhaps correct your command pulling the resource from the bundle. Instead of
[NSBundle pathForResource...
it should be
[[NSBundle mainBundle] pathForResource...

Nib files cannot be loaded by name from main bundle

It seems as though my nib files are included in my test target, they don't exist in the main bundle, so my app crashes on me when I am loding a nib by its name from the main bundle. I either need to find the correct bundle that includes my nib file, or I need to load a nib using a path.
Does anyone have a solution for either one? [NSBundle bundleForClass:[self class]] doesn't work. I think the nib and class files are not in the same bundle
It might help to enumerate the bundles
for (NSBundle *bundle in [NSBundle allBundles])
{
// can look for resources in bundle
locatedPath = [bundle pathForResource:resourcePath ofType:type];
// or maybe trying and load the nib from it?
UINib *nib = [UINib nibWithName:#"Blah" bundle:bundle];
// check for !nil ...
}

Adding CoreData to existing Project

I am trying to add CoreData to an existing project and
there is strange error...
I get the error:
Terminating app due to uncaught exception
'NSInvalidArgumentException', reason:
'Cannot create an
NSPersistentStoreCoordinator with a
nil model'
in RootView there is a warning in:
- (NSFetchedResultsController *)fetchedResultsController;
in line:
_fetchedResultsController.delegate = self;
and it says:
warning: class 'RootViewController'
does not implement the
'NSFetchedResultsControllerDelegate'
protocol
any ideas?
argh!
sorry for even asking, I just missed that I changed the name of .xcdatamodel
I needed just to change the name in managedObjectModel and persistentStoreCoordinator
hope it'll help someone anyway.
I was getting the same exception.
My issue was that I had added the .xcdatamodeld file in the root directory of the project (with siblings Frameworks and Products) instead of in the folder named after the project (with siblings Supporting Files, AppDelegate.h, etc.)
I tracked it down to this line: NSURL *modelURL = [[NSBundle mainBundle] URLForResource:#"Foo" withExtension:#"momd"];
In this method: - (NSManagedObjectModel *)managedObjectModel