problems with loading nib files
problems with loading nib files
- Subject: problems with loading nib files
- From: Paul Cezanne <email@hidden>
- Date: Tue, 7 Jan 2003 16:06:28 -0500
If this is answered in the archives, I'm sorry. I've been reading them and I just don't see it. I've also looked in Hillegass and Anguish and have come up short.
Anyway, my problem.
I have a working application with used to have one nib file. I need to make 2 applications for 2 different clients, the underlying code base is essentially the same, look and feel essentially the same. Note, this is similar to, but different, from localization. I do have this application localized (in theory, I call all the right calls for my strings at least, but not my widgets), I'm making 2 separate applications and only shipping one of them to an end user.
Graphics and menus are different, (the menu says App1, About App1 etc... or App2, About App2 etc...) In the future I may want to change window shapes or other UI elements.
So I cloned the single target and made 2 new nib files, App1.nib and App2.nib and added App1.nib to the App1 target and did the same for App2. The nib files have graphics and MainMenu in them. The File's Owner's class is CMainController (I tried NSApplication also). I deleted MainMenu from the MainMenu.nib file.
I then look around for a place to load the nib and the archives showed that some developers were loading them in a controller awakeFromNib method and some were doing it in init. Everybody was doing it to either load an additional controller or class.
awakeFromNib didn't work, infinite loop city. So I coded up an init method and put in on one of my controllers (I have many controllers, all loaded from the MainMenu.nib)
- (id)init
{
[super init];
#ifdef APP1
[NSBundle loadNibNamed:@"App1" owner:self];
#endif
#ifdef APP2
[NSBundle loadNibNamed:@"App2" owner:self];
#endif
return self;
}
The preprocessor definitions APP1 and APP2 are defined by ProjectBuilder as appropriate for the target being built, only one is defined. The plist is also different.
Things seem to work well now, I get my graphics, my menus are correct, they trigger the right actions but there is one thing wrong.
I call CMainController's awakeFromNib twice. Once in the normal fashion (from main), and the call to loadNibNamed also triggers a call to CMainController's nib file.
This is bad. I'm sure there are Cocoa reasons why this is bad but as far as my application is concerned this is bad.
So, thansk for reading this far, and now for the questions:
1) where should I be calling loadNibNamed to load graphics and menus?
2) is this the right approach to getting 2 similar applications?
Also, I'd like to be able to put more than just graphics and menus in the nib file someday, a good solution will permit that. Additionally, I'll need to break out my UI from MainMenu.nib since I really want to have more than one window. I just some postings which talking about calling loadNibNamed to bring up new windows. I'm not sure the document model fits my application, but I'm looking into that.
Thank you!
Paul
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.