From: Sherm Pendley Date: 2007-05-08T10:45:08+09:00 Subject: Re: RubyCocoa Sheets - help anyone? Tim Perrett writes: >> That calls for a drink! (Pours a pint of Guinness...) > > hahaha i know! Beers all around....!!! > > >>> @mainWindow, nil, nil, nil) >> OSX::NSBundle.loadNibNamed_owner ("Prefs", self) > > You include a bit of my begin sheet code here, i guess that needs to > stay pretty much as is, just with the load for the actual sheet > changing? > > >> 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 make an interesting point there - the code that is actually doing > this (or will ultimatly be doing this rather) is in a subclass of > NSWindowController - im guessing I cant instansiate the controller > within IB so i'll have to go for the file owners approach? Right. You can't instantiate a new controller instance in your Prefs NIB, because you want to re-use the one that already exists in the main NIB. > How do i set the class as the files owner, do i make it the file owners > delegate connection by dragging the connection in IB? In your Prefs NIB, create your NSWindowController subclass. (You're not really creating a new class, just telling IB about your Ruby class. You need to do it manually because IB doesn't grok .rb files.) Be sure to add the outlet for the Prefs window you'll be using as a sheet. Then select the "file's owner" and select your Ruby class in the "custom class" pane of the info panel. Again - this doesn't create an instance of your controller class, it just lets IB know that, when this NIB is loaded at run time, what class its owner object will be an instance of. This is how IB knows what outlets and actions to show in the "connections" pane of the Info panel. That's a key point, worth repeating: You're not creating any new classes or instances with these two steps. All you're doing is making IB aware of what you've already created in code. All that's left is to make the connection to the outlet. Just control-drag from the "file's owner" to the prefs window, select the outlet you want to connect it to, and click the "connect" button. Now, when you call loadNibNamed_owner(), the connections you've defined in the NIB will be made to the object you pass as the second argument. > What you are saying however is that my controller for any given > window can load in the 2nd nib file, then reference itself as the > provider for that sheet with its newly loaded contents? I'm not certain what you mean by "provider" here, but I guess you mean to say "owner". Yes, that's one key difference between the two techniques. When you instantiate an object inside of a NIB, you can only control-drag connections to it from other objects inside that same NIB. But, when you instantiate your controller in code, you can then pass it to as many loadNibNamed_owner() method calls as you'd like. You'll have one common controller object whose outlets are connected to objects in as many different NIB files as you need; all you need to do is control-drag the connection in each NIB to the "file's owner" icon. sherm-- -- Web Hosting by West Virginians, for West Virginians: http://wv-www.net Cocoa programming in Perl: http://camelbones.sourceforge.net