Using NSPanel with IB

Member
Posts: 156
Joined: 2002.10
Post: #1
Ok, first off, I'm a complete beginner with Cocoa, so please be nice to me Smile

What I'm in the process of doing is writing some code to allow SDL users to pop up Cocoa dialog boxes, and then query the results of user input when the dialog boxes are closed.

So what I've done is to draw out an NSPanel in IB, and created a custom sub-class. I did this so that I could have outlets for each of the controls of interest e.g. text boxes, radio buttons, or whatever is on the panel.

Then I generate the code for my custom subclass in IB, and add the files to my Xcode Project.

Now when I do [[Custom Window] alloc] init] setIsVisible:YES]; I get a small floating window, but it's blank, with no controls on it.

What is the proper way of doing this so that the controls appear correctly? If the answer is 'go and learn Cocoa properly' then that's fair enough, but any pointers to something specifically relevant would be great.

Cheers

- Iain
Quote this message in a reply
Member
Posts: 116
Joined: 2005.02
Post: #2
1. Do you think you made the controls invisible by accident?
2. If that isn't true, try coding in the controls
3. If all else fails, go learn Cocoa correctly

Last login: Sat Aug 6 09:15:05 on console
Welcome to Darwin!
Matt-Chelens-Computer:~ matthew$
Quote this message in a reply
Sage
Posts: 1,403
Joined: 2005.07
Post: #3
Try using makeKeyAndOrderFront:(id)sender (sender can be NULL), instead of setIsVisible.

Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote this message in a reply
Member
Posts: 156
Joined: 2002.10
Post: #4
Thanks for the replies so far. The controls are definately not invisible. I could code them in by hand, but that negates the whole point of using IB. If I understood it correctly the point of using a NIB was to set up things graphicall and saving code.

Also, the window that pops up is the wrong size (a smallish square) - it looks precisely like a default, unaltered NSPanel should look like, not like my nice dialog box from IB.

- Iain
Quote this message in a reply
Member
Posts: 114
Joined: 2005.03
Post: #5
The problem is that your allocating the class, but you're not creating the controls. The subclass does not contain any code to create these controls. Instead, they are in the .nib-file and work only with the specific window object you created in IB.

What I would do: Either hardcode everything, use something completely different if possible (NSAlert maybe?), try to load the .nib every time new (I don't really know how to do this) or post the question here.
Quote this message in a reply
Member
Posts: 156
Joined: 2002.10
Post: #6
OK, from the responses so far, I think I'm not phrasing my question correctly, so I will try again...

How do I load an object (e.g. a customised NSPanel) from a nib file so it will display with all the controls etc. on it.

Cheers

- Iain
Quote this message in a reply
Sage
Posts: 1,403
Joined: 2005.07
Post: #7
You should put your Custom panel in a seperate nib file from the mainmenu nib and then use [NSBundle loadNibNamed:@"whatever" owner:self], so load a copy of that nib, loading the panel too. You can look at the code for document based applications like Sketch and TextEdit, for how to communicate with the nibs

Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote this message in a reply
Post Reply