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.


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.)


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.

The problem is that when i try setting this up i get the following error on build:


2004-08-10 15:24:41.964 PerlButtonTest[995] Could not connect the action showPreferences: to target of class NSApplication

I am sure I do not have something connected correctly in XCode/IB. The ShuX code uses a window and I am using a panel. (The Objective C book I am using is "Cocoa Programming For Mac OS X second edition" by Arron Hillegass. His examples use a panel for preferences instead of a window.)

Still not certain where I am going wrong...



Reply via email to