Re: programmatically drawing an NSImageView in an NSView subclass
Re: programmatically drawing an NSImageView in an NSView subclass
- Subject: Re: programmatically drawing an NSImageView in an NSView subclass
- From: John Randolph <email@hidden>
- Date: Mon, 12 Jan 2004 15:07:58 -0800
On Jan 10, 2004, at 11:31 AM, Benjamin Salanki wrote:
- (void)drawRect:(NSRect)rect
First thing: -drawRect: is for drawing, not for file I/O. -drawRect
can be called at any time, and the code you have below will leak as
many NSImageView and NSImage objects as you have entries in _files,
*every time* your view is told to draw itself.
{
//drawing code here
int numberOfFiles = [_files count];
int i;
for(i=0;i<numberOfFiles;i++)
{
NSImageView* theView = [[NSImageView alloc]
initWithFrame:NSMakeRect(15+(i%3)*85, 15+(i/3)*72, 70.00, 56.00)];
[theView setImageFrameStyle:NSImageFramePhoto];
[theView setImageAlignment:NSImageAlignCenter];
[theView setImageScaling:NSScaleProportionally];
[theView setImage:[[NSImage alloc] initWithContentsOfFile:[_files
objectAtIndex:i]]];
[theView setTag:i];
[theView setTarget:self];
[theView setAction:@selector(what:)];
}
}
any ideas?
You're never adding theView to the view hierarchy, so it isn't
associated with a window or any other graphics context, so it has
nowhere to draw.
I would suggest that you write a separate method to load the images,
and use NSImage's -compositeToPoint:... or -drawInRect:.. methods to do
the drawing.
-jcr
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.