Reputation: 8163
Is there anyway to do it?
I've tried pathForResource:ofType:
on NSBundle and it can't find the xib when it's really there. If I try to load it and it doesn't exist loadNibNamed:owner:options:
crashes and so does nibWithNibName:bundle:
Basically, I want to know at runtime whether I should register a xib or just a class for a given cell type on a collection view.
Upvotes: 1
Views: 1987
Reputation: 6393
Are you sure pathForResource:ofType:
is not working? It's not just the common xib / nib confusion?
(.xib-files are ofType:@"nib"
)...
NSBundle *mainBundle = [NSBundle mainBundle];
NSString *path = [mainBundle pathForResource:@"crapXib" ofType:@"nib"]; // file is called crapXib.xib
if (path){
// whatever...
} else{
// whatever else
}
Upvotes: 6
Reputation: 5684
You can try to use NSFileManager
to check if file exists, if application is not localized all .nibs
live in root directory of .ipa
, for example:
NSString * root = [[NSBundle mainBundle] resourcePath];
if ([[NSFileManager defaultManager] fileExistsAtPath: [root stringByAppendingPathComponent:@"MainViewController.nib"]])
{
// exisits
}
Upvotes: 0