On Aug 6, 2004, at 11:16 PM, Sherm Pendley wrote:
On Aug 6, 2004, at 7:01 PM, Alan Olsen wrote:
This is probably simple, I am just not seeing it.
It's simple in hindsight, but it can be difficult to get your head around it at first.
Especially when you are not used to Objective C and the methodology used in connecting everything together.
I have a couple of dialog boxes that are getting called in specific cases. (A preferences panel and a couple of other panels needed to select data.)
I am not quite understanding how to call the various panels. I know i need to connect something to something in the xcode interface, but I am not certain what.
It's not done in Xcode, but in Interface Builder. You create a new Nib with whatever panel(s) and such you want in it, and add that Nib to your project. (Okay, I lied - part of it is in Xcode.)
Sometimes hard to remember that interface builder is a separate app...
Moving things between nib files works with copy and paste. I wish that drop and drag worked. It is a bit more "intuitive". (Though "intuitive" and "Cocoa programming" do not seem to be intersecting sets.)
In the MainMenu Nib, connect the "AppName Preferences" to an action method in AppName.pm. In that action method, create a new controller object. Here's an example from ShuX:
sub showPreferences { my ($self, $sender) = @_; unless (defined $self->{'_preferences'}) { $self->{'_preferences'} = new PreferencesDelegate; } $self->{'_preferences'}->{'Window'}->makeKeyAndOrderFront(undef); }
In the constructor for the PreferencesDelegate class, create an NSWindowController and use it to load the Nib, telling it that the current object is the Nib's "owner". Thus, action messages you've connected to the "File's Owner" in IB will be sent to this object. Here's part of the PreferencesDelegate new() method from ShuX - I've deleted some code that isn't relevant:
sub new { # Typical Perl constructor # See 'perltoot' for details my $proto = shift; my $class = ref($proto) || $proto;
my $self = { };
bless ($self, $class);
$self->{'wc'} = NSWindowController->alloc->initWithWindowNibName_owner("Preferences", $self);
$self->{'wc'}->window;
return $self; }
Once you call NSWindowController's initWithWindowNibName_owner() method, the outlets that you've connected in IB will be connected to the corresponding outlets declared in your Perl code, and action methods sent by the Nib will be sent to the newly-created object.
You can also use the same technique to create multiple instances of the same Nib, each owned by a different controller object - ShuX does this to manage multiple browser windows.
I will try that. I need to reorganize things before I can do that. (I have everything crammed into the same nib.)
The only thing really left after this is getting NSTableView to work. (I have example code for that. I will work o that once I have this solved.)
Have you looked at the "Data Access" example app?
No I had not. That is very useful.