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: p3consulting <email@hidden>
- Date: Tue, 13 Jan 2004 09:11:29 +0100
It could not work because views must belong to a view hierarchy to be
drawn :
your NSImageView is never added to the view hierarchy ([self
addView:theView] is missing) and drawRect is certainly not the good
place to add subviews
to a view the idea to call initWithContentsOfFile from drawRect will
certainly not help the performance to say the least
You should have other methods of your own to add/remove/move NSImage
subViews in your NSView subclass, these methods should be called
to respond to user actions and end with a [self setNeedsDisplay:YES]],
then you down need to overwrite drawRect at all
The view hierarchy mecanism will do the necessary for you.
If you want the user to drag NSImageView from their superview see
http://www.macosxguru.net/article.php?story=20031219104032813.
Pascal Pochet
P3 Consulting
On 10 janv. 2004, at 20:31, Benjamin Salanki wrote:
hi,
i want to draw some NSImageViews in my NSView subclass.
i use the following code in my drawRect: method:
- (void)drawRect:(NSRect)rect
{
//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:)];
}
}
the calculations get done and everything, CPU cycles get eaten, but the
view does not display the imageViews. I tried to replace the code and
draw simple rects with NSBezierPath, and that works like a charm.
any ideas?
thx,
Ben
stupidFish23
http://www.stupidfish23.com
_______________________________________________
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.
_______________________________________________
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.