views:

353

answers:

1

If I have a directory in my Xcode project (not a Group), which is added to the main target, and compile it, how do I instruct an NSViewController to initWithNibName:bundle: a nib file inside that directory?

I've tried [viewController initWithNibName:@"FolderName/NibName" bundle:nil], but that doesn't work. Neither does without the folder name, nor setting the bundle parameter to [NSBundle mainBundle]. I've even tried setting the bundle to [NSBundle bundleWithPath:pathToFolderName] to no avail.

+2  A: 

You're best off not using folders like this. Many Cocoa conveniences like -[NSImage imageNamed:], or the view controller init method expect to find a file in the Resources folder of the bundle.

If you'd really like to keep a folder of NIB files anyway, you can, but you won't be able to use the convenience methods. You can override -[NSViewController loadView] method of your view controller to invoke -[NSBundle loadNibFile:externalNameTable:withZone:]. You would pass the path to the NIB file, a name table with NSNibOwner set to the view controller, and a NULL zone. You'll also need to take care of releasing the top level objects from the NIB file.

Things will go a lot smoother if you abandon the sub directories in Resources.

Jon Hess