Referencing A Nib File In A Subfolder Of An Xcode Compiled Cocoa App Bundle
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.
Answer
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.
Related Questions
- → Shopify iOS SDK - issue converting BuyProductVariant to BuyProduct
- → BigCommerce and shopify API
- → How to print the cart items,remove cart items in shopify ios sdk?
- → How to keep the user logged in or check if the user is logged in or not in Shopify?
- → How to covert a custom class into json array or json dictionary in objective c?
- → React Native Debug iOS Component in XCode
- → Error tokenizing data. C error: EOF following escape character
- → data type understanding of Parse database
- → How to save the response From My server , and How can i access That data
- → Bulk creation of components in React Native
- → How to mute AVAudioPlayer if music from another app is playing in spritekit
- → Swift Array memory address changes when referring to the same variable
- → String encryption in Objective-C decrypt in C#