Re: main nib, secondary nib, where do the outlets get connected to in the main nib?
Re: main nib, secondary nib, where do the outlets get connected to in the main nib?
- Subject: Re: main nib, secondary nib, where do the outlets get connected to in the main nib?
- From: Dustin Voss <email@hidden>
- Date: Sat, 24 Jul 2004 12:01:26 -0700
On 24 Jul, 2004, at 8:44 AM, John Spicer wrote:
The main file has a menu with items on it. Each item on the menu is
connected to the instantiated controller. That controller (in code)
has a method that loads the nib file and makes the window the active
window (part of this does not work: the window loads and displays but
it's not active until you click on it).
Did you try -makeKeyAndOrderFront: ?
So the target is connected from the menu (in the main nib) to the
action in the controller class. So far, so good.
However, according to the docs one also creates an outlet in the
controller item as well (it's used in loading the nib so it must be
needed!)
Where is this outlet connected to in the nib file?
I'm asking for two reasons:
[1] unconnected outlets annoy me, seems they should be hooked to
SOMETHING!
[2] it's possible (I don't know) that not having this outlet connected
is what's causing the window when loaded to not be the active one.
I am not sure I understand. An outlet is simply a variable, whose value
is something in the NIB. You create outlets in your controller class so
your code can access the NIB's UI elements. You don't have to create an
outlet for every UI element; in particular, you don't typically need to
make one for static UI elements because you never change their state.
To make use of an outlet, you have to create it in your controller
class and connect it in IB. Then, when the NIB is loaded, the outlet
variable gets assigned an instance of the UI element. It sounds like
you may not have connected it.
To create the outlet, just declare a variable like
IBOutlet NSTextField *theTextField;
in your controller class's .h file, save the file, and update IB's
database (as described below).
To connect an outlet of a controller instantiated in the NIB, to a
particular UI element, make sure you see the "Connections" inspector
panel, and control-drag from the icon representing the controller, to
the UI element. The inspector should show the controller's outlets.
Just select the right one (compatible outlets should be bold-faced) and
click "Connect". That should connect the outlet to the UI element.
If an outlet you know is there is not showing up, you probably added
the outlet to the controller class without telling IB about it. IB
maintains a database of outlets for each class rather than checking the
source code directly. You can force it to update its database by
re-reading the appropriate header file. To do that, select the icon
representing the controller class and select the "Classes" tab in the
NIB-file window. It should highlight the controller class in the
NIB-file window. Then go to the "Classes" menu and re-read the header
file. That should update the database.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.