Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Fiddlestick

macrumors newbie
Original poster
Jul 16, 2009
2
0
I'm quite new to ObjC and Cocoa, but I have good general programming experience in PHP and Java.

I've done some GUI programming in Java using Swing and AWT and I'm finding Interface Builder extremely refreshing and simple to use, but I'm not quite clear when I should be using multiple nib files.

To give an example, I play a popular mmorpg and it provides an API so that players can build tools to download account and character information, so I'm building myself a little tool as it would be a useful thing to have and it would help expand my Cocoa/ObjC knowledge.

A typical use case would be going to a menu from the menubar and clicking an option to add a character. At this point a window would pop up with the character manager, and you would click buttons that would make other dialogue boxes pop up so you can enter your API details and what not.

In Swing I would just generate a new window for this and my listener would read in the details and pass them back to the main execution loop, but I'm not quite sure how I would go about this in Cocoa.

Would I have separate windows that are hidden by default and only appear when you want them to become visible, or would I instead store the windows in seperate nib files, load them on demand and then have them grab focus so that you can't return to the main window until you dismiss the new window?

I hope what I'm trying to do makes sense. I'm enjoying myself so far, but this is part of the Cocoa methodology that I don't quite "get" yet.
 

GorillaPaws

macrumors 6502a
Oct 26, 2003
932
8
Richmond, VA
...or would I instead store the windows in seperate nib files, load them on demand and then have them grab focus so that you can't return to the main window until you dismiss the new window?

This is how it's normally done, although I'm not sure if you need to make your window modal (locking focus until completed). You might want to look into the responder chain, the first responder and nil-targeted actions, to get a sense of how focus shifts around. Typically, you should avoid modal windows unless it's absolutely necessary.
 

Fiddlestick

macrumors newbie
Original poster
Jul 16, 2009
2
0
Thanks, that's what I suspected.

I take it when I wanted to use it I would instantiate a reference to the nib and then issue some sort of awakeFromNib message to and then make my windows visible?
 

GorillaPaws

macrumors 6502a
Oct 26, 2003
932
8
Richmond, VA
Thanks, that's what I suspected.

I take it when I wanted to use it I would instantiate a reference to the nib and then issue some sort of awakeFromNib message to and then make my windows visible?

You're going to want an NSWindowController object to manage that window and it's contents. Also, you might want to consider using an NSPanel for what you're trying to do (panels are just special windows so they still have NSWindowControllers).
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.