0
votes

I'm trying to load NiB files from subfolders based on some condition at runtime. The problem is that the code is able to locate the NIB file when i call the method pathForResource but when i run the application i always get the following error

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle

Here's my code:

// The designated initializer. Override to perform setup that is required before the view is loaded.

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {

if(somecondition == true)
{        
    NSString* nibPath = [[NSBundle mainBundle] pathForResource:nibNameOrNil ofType:@"xib" inDirectory:@"CAS"];
    NSString* customPath = [nibPath stringByDeletingLastPathComponent];

    NSBundle* localeBundle = [NSBundle bundleWithPath:customPath];

    if (localeBundle!= nil) { 
        nibBundleOrNil = localeBundle;
    }
}

}


if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {

}

return self;
}
1
It's [NSBundle MainBundle]; and I think you are confused as to the structure of the so called "folders" in Xcode. When Xcode creates a folder, it just edits your project's XML to include those files in a pseudo-folder bundle. It never actually writes to the file system.CodaFi
so what is the 'inDirectory' field used if there aren't 'folders' ?ArdenDev
It's supposed to imply that you make reference to a file in your bundle such as the NSHomeDirectory or the NSDocumentsDirectory.CodaFi

1 Answers

1
votes

Your NIB / XIB should be included in your xCode project. They should be in the same folder. You can only load NIB / XIB imported to your project.