Lefora Free Forum
login join
Loading
733 views

Passing an argument when opening an XIB file?

Page 1
1–5
rookie - member
3 posts

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

?
288 posts

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.

__________________
rookie - member
3 posts

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

?
288 posts

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?

__________________
rookie - member
3 posts

Ahh yeah, I could use that! Didn't even think of that! I'll probably still stick to doing it "properly" in Objective-C but that's interesting to note.

- Javawag

Page 1
1–5

Locked Topic


You must be a member to post in this forum

Join Now!