• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Drawing an image in a CustomView
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Drawing an image in a CustomView


  • Subject: Drawing an image in a CustomView
  • From: Mike Brinkman <email@hidden>
  • Date: Mon, 14 Jan 2002 22:46:40 -0500

I tried to get something out of "Cocoa Programming", but obviously missed
the point.

I created a new project called "SimpleImage". The goal is to draw an image
in a window.

I then created an Obj-C NSView subclass called "simpleImageView.m" and it's
header "simpleImageView.h".

I double-clicked on "MainMenu.nib" to launch Interface Builder.

I dragged "simpleImageView.h" into "MainMenu.nib".

I dragged a CustomView onto the window.

I clicked on "simpleImageView" under CustomView's attributes and saved.

Here are my files:

/* simpleImageView.h
*********************************************************************/

#import <AppKit/AppKit.h>

@interface simpleImageView : NSView {
NSImage *image;
}

- (void)setImage:(NSImage *)x;

@end


/* simpleImageView.m
*********************************************************************/
#import "simpleImageView.h"

@implementation simpleImageView

- (id)initWithFrame:(NSRect)frame {
self = [super initWithFrame:frame];
if (self) {
// Initialization code here.
}
return self;
}

- (void)drawRect:(NSRect)rect {
// Drawing code here.
image = [[NSImage alloc] initWithContentsOfFile:@"macosxlogo.gif"];
[simpleImageView setImage:image];
}

- (void)setImage:(NSImage *)newImage
{
[newImage retain];
[image release];
image = newImage;
[self setNeedsDisplay:YES];
}

@end

Here are my ERROR MESSAGES:
2002-01-14 22:32:06.780 SimpleImage[394] *** +[simpleImageView setImage:]:
selector not recognized
2002-01-14 22:32:06.851 SimpleImage[394] An uncaught exception was raised
2002-01-14 22:32:06.872 SimpleImage[394] *** +[simpleImageView setImage:]:
selector not recognized
2002-01-14 22:32:06.889 SimpleImage[394] *** Uncaught exception:
<NSInvalidArgumentException> *** +[simpleImageView setImage:]: selector not
recognized

SimpleImage.app has exited with status 255.


I'm sure this is probably the type of thing that would take 2 lines of code,
instead of all the stuff I tried to write right here. Maybe somebody could
help me out?


  • Follow-Ups:
    • Re: Drawing an image in a CustomView
      • From: "Erik M. Buck" <email@hidden>
    • Re: Drawing an image in a CustomView
      • From: Enigmarelle Development <email@hidden>
  • Prev by Date: Re: NSWorkspaceDidTerminateApplicationNotification bug?
  • Next by Date: Faceless Background Application
  • Previous by thread: -LoginHook not working?
  • Next by thread: Re: Drawing an image in a CustomView
  • Index(es):
    • Date
    • Thread