Passing an argument when opening an XIB file?
Hi all,
First post!
Basically I'm making an chatbot app which can have many dictionaries, each with different vocab. When the app opens, the MainMenu.xib only has a main menu, which contains a New and Open command - when I click Open, I want to ask for a dictionary file (I can do this bit), and then open another nib file containing the main interface, passing the dictionary filename as an argument. At the same time, I want New to ask where to save the dictionary (I can do that), and then open the main interface again, but this time with a blank file.
The code i'm using is:
[NSBundle loadNibNamed: @"DictionaryWindow" owner: self];
but I can't pass any data to the nib which the window can access (so it has no idea what file it's opening!!)
Anyone know how to do this? Do I need to have the window in the same nib file and do something else? Or can I pass an argument with the code I already have?
Thanks in advance =)
- Javawag
I think you're saying that you'd like to localize your application (and use a different nib for different locales). Apple provide support for this: http://developer.apple.com/internationalization/
I recommend you take a look at Apple's sample code and that'll probably explain how to achieve the result for which you're looking.
Not exactly... what I meant was I wanted to open an NSWindow inside another NIB file and send it some data (i.e. an NSString). The way I've done this now is to use a method in a controller class in the NIB I'm opening... that way I can send the NSWindow information about which file it needs to open.
Thanks for the reply though =)
- Javawag
You get called (awakeFromNib) in any objects in that are in the nib. So, although it appears that you can't pass arguments on the NSBundle::loadNibNamed, your code will execute during the loading process. If you hold the prized data in a extern object (boring old C extern - nothing magical), your loading nib object can access it.
Does that fix it - or have I still failed to understand what you're looking for?