# Cocoa Buttons Linked To Windows



## qbkd10 (Nov 20, 2007)

I am creating a very basic application for the Mac in Cocoa, and I am trying to link an NSButton instance to open a window. How would I go about this in IB3?


----------



## Mikuro (Nov 26, 2007)

I'm still using IB2, but I assume the procedure is the same in IB3:

Hold down the control key, and drag from the button to the window's icon in the "instances" tab of the main nib window. You'll see a list of actions appear in the Inspector palette. Connect it to "makeKeyAndOrderFront:". That should do it.


----------



## qbkd10 (Nov 26, 2007)

Nah, that's not helping, it won't let me make a connection between the button and the window's instance. Any other ideas?


----------



## Mikuro (Nov 26, 2007)

Hmm. Maybe the button is already connected to something else, in which case it wouldn't allow new connections (it would instead bring up the outlets panel). You could try with a new button, or select the existing button and double-check that it's not connected to anything by going to the Inspector's "Connections" section and selecting the Target/Action tab.


----------



## qbkd10 (Nov 27, 2007)

Yeah, no connections. Triple-checked. Something's really weird here...


----------



## HateEternal (Dec 3, 2007)

Make sure you select the button first. The attached nib file has a window with a button, when you click the button another window will display or come to the front. For some reason when I test the interface the second window is always visible. I _though_ that was controlled by 'Visible at launch' controlled but it doesn't seem to work quite as I expected. Run it using the Simulate Interface option under File in Interface Builder.


----------



## qbkd10 (Dec 6, 2007)

OK, works now, thanks guys!


----------



## qbkd10 (Dec 6, 2007)

Wait, just another question, how would you go about doing this with AppleScripts as opposed to opening windows?

*EDIT:* Never mind. I'll just post a new thread.


----------

