Menus Not Loading From Nib - Printable Version
+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Game Programming Fundamentals (/forum-7.html)
+--- Thread: Menus Not Loading From Nib (/thread-4578.html)
Menus Not Loading From Nib - kodex - Jan 27, 2006 11:24 PM
Im wrapping up my latest game and I just got around to the menu bar (that shows during windowed mode), I really dont use it since I have in game menus that handle everything. The problem is its there and it wont change.
The first issue is I have two of them, If I select quit from the first one the menu closes and goes to the other one. I assumed a long time ago that I could grab the event from the first quit and pass it to my games quit function.
The problem I am having is I seem to have no control over the menu, Im attempting to load it from my nib to change the menu title (since its still generic). I using the following code
I get no errors up until the SetMenuBarFromNib, where it fails with a iErr = -10, I trippled checked the name of it and even attempted to change it. Is there a reason I am missing on why it wont load the Menu? Im kinda stumped on this because all the documentation I found says this should work fine.
Thanks for the help as always everyone. =)
Menus Not Loading From Nib - dair - Jan 28, 2006 01:53 PM
That code looks fine - my guess would be that you're either loading the wrong bundle, or you don't have the menu in the nib you're loading. Perhaps try using CFShow to dump out the bundle and nib, and double-check the menu name in the nib file is correct?
You can see similar code in /Developer/Examples/Carbon, so you may want to use that as a test case to see what's different.
Menus Not Loading From Nib - kodex - Jan 28, 2006 02:55 PM
Everything checks out, tripled check the names on everything again, and I only have one nib file. I'll toy around with it some more, but if anyone else has any suggestions im all ears.
Menus Not Loading From Nib - kodex - Jan 28, 2006 03:16 PM
I added in some error handlers, according to the documentation it should fail only because one of these three reasons, It dosnt return anything that matches them and I get an unknown error (-10). Just thought I would provide some more info incase anyone was thinking about it besides me.
Menus Not Loading From Nib - dair - Jan 29, 2006 12:23 PM
Is it possible that you're not launching the copy of the app you think you are? I.e., if you insert a CFShow(gBundle) after CFBundleGetMainBundle, does that print the path you'd expect? And if you open up that app's package, and load its .nib into IB, the menu bar is present?
Your code is fine - if you create a new Carbon Application in Xcode, and paste it into main, then after changing "Game" to "main" and "MainMenu" to "MenuBar" then you'll see everything get loaded up as you expect.
So if the code is fine, the problem must be in the .nib - either the wrong one is being loaded, or the one you've got has a problem in it. CFShow/Show Package Contents should rule out the first, and for the second you might want to look at the objects.xib file inside your .nib package.
This is just a text XML file that defines the objects in the .nib, but will let you confirm it's not something like a stray space character at the end of the menu name.
If there's no obvious problems with it, I would try creating a new nib from scratch and confirm you can load a menu out of that - I suppose it's possible your existing .nib has been corrupted somehow, although you'd think if that was the case then IB would also refuse to load it.
Menus Not Loading From Nib - kodex - Jan 29, 2006 04:52 PM
Amazingly that works but dosnt really slove my problem, I still cant change the name of the application through the menu bar. Although I can now catch the quit command.
Thanks Dair, it must of been corrupted somehow. I do have a second followup question is there a way to change the application name after I create a project or should I create a new project and import all my source files?
Menus Not Loading From Nib - dair - Jan 30, 2006 08:01 AM
The string displayed at the top of the application menu is set by the CFBundleName value in your Info.plist (or localised equivalent).
I don't believe there is any supported way to change this at runtime, so you'll need to set an appropriate CFBundleName value before you are launched.