Thursday, February 15, 2007

Using custom panels in Objective-C

Okay, so here was a problem that was presented to my by the Objective-C Language. Lets say in my .nib file, I have a custom panel to create a new person and add them to the database. In C#, I just call the name of the file to instantiate it. I tried to do the same in Objective-C. Well, there is a problem, a .nib file isn't really a class. It is a resource that contains GUI information. So, I had to sit down and figure out how to make my custom panel display on demand. After an hour, I figured out how.

To use a custom panel in Objective-C, you need to create it in your .nib file. After you do so, you need to create a handler for it and your main window. The easiest way to bypass this problem is to just create a reference (An Outlet with NSPanel or NSWindow for its type) to the window and the custom panel in the handlers. So then, if you want to make them appear all you have to do is call the method [panelName makeKeyAndOrderFront];

That's about it. A simple solution to the problem. Now I am sure that there is another way that is probably easier to work with, but this is a quick and pretty easy solution to my problem.

Hope this helps!

No comments: