Question

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.

Was it helpful?

Solution

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
}

OTHER TIPS

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
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top