Tim P. [email protected] writes:
It now raises a sheet! horay!
That calls for a drink! (Pours a pint of Guinness…)
@mainWindow, nil, nil, nil)
OSX::NSBundle.loadNibNamed_owner (“Prefs”, self)
The outlets were then linked up in IB correctly. This all works hunky
dory However, I would prefer it if the sheets that I load were in
external NIB files to keep things nice and tidy.
That’s where the loadNibNamed_owner() method comes into play. You’d
define
your class in the NIB that holds the sheet, tell IB that the file’s
owner
is an instance of that class, and connect the file’s owner “prefsWindow”
outlet to the sheet.
What you do not want to do is instantiate your Ruby class in
Prefs.nib.
Doing that would result in two instances of your controller object,
one
in each NIB.
Given that when I am using a single NIB I could hook up the sheets using
IB but presumably when using external NIBs i will need to replace this
hooking up in IB with somthing more programatic?
No, your outlets are still connected in IB.
The difference is what you connect them to. It sounds like you’ve
created
an instance of your Ruby class in your main window NIB, which is
represented
by the “blue cube” icon. When that NIB is loaded, Cocoa’s NIB loading
machinery will create a new instance of your class, and then connect the
outlets you’ve defined.
But, if you set the class of the “file’s owner” in IB to your Ruby
class,
Cocoa will not create a new instance when the NIB is loaded. Instead,
it will use the instance that was passed as the second argument to the
loadNibNamed_owner() method, and connect the outlets to that.
The key in all this is whether you want your controller object to load
your
NIB, or the NIB to create the controller. If you want the former, you
set
up the “file’s owner” connections. For the latter, you instantiate the
object in IB, and set up the connections to that instead.
You can also do both. You can instantiate your controller in your main
NIB,
and connect its outlets to the “blue cube” icon in that NIB. Then, you
can
load a secondary NIB using loadNibNamed_owner() - in the secondary NIB,
the
outlets would need to be connected to “file’s owner”.
sherm–