Ah, a few problems.
First of all, as a general rule, capitalize the first letter of each class you define. Instances of those classes should be non-capitalized. (e.g. a
Box named
box.) Obviously, this won't fix any errors, but it makes your code cleaner and easy to understand (i.e. I see something captialized, it's a class...)
Second, about the way things are hooked up. Your controller shouldn't be hooked up to something called "displayImage." Hooking up something to an outlet only means that you have an instance variable which is initialized properly and that you send messages to.
Third, there's no need to subclass the image view. You just want to send it a message telling it to display a certain image. NSImageView already has that method built-in.
Fourth, if you want something to receive a notification, you should hook it up to the File's Owner as its delegate.
Let's start from the beginning, here's how it _should_ look:
You have a fresh project. Open up the nib file, and subclass NSObject, name it "Controller." Add an outlet called "imageView." Create the files necessary... Instantiate the Controller. Drag an NSImageView from the Cocoa palette onto your window, but don't subclass it.
Right now, you have all the objects you need.
The File's Owner has an outlet called "delegate." Connect that up to your controller. It'll now receive the notification.
The Controller should have an outlet called "imageView." Connect that up to your NSImageView. That will let it communicate to the imageView.
Now, in your Controller file, create the applicationDidFinishLaunching: just like you did, with the following code:
Code:
- (void)applicationDidFinishLaunching :(NSNotification *)not
{
[imageView setImage:[NSImage imageNamed:@"ImageName"]];
}
Try that. Although getting the image's path from the bundle will work, imageNamed is a much quicker solution.
- EDIT: Darn smilies! :-)
------------------
http://gilgalad.dyndns.org/
[This message has been edited by parallax (edited 04-30-2001).]