• 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
Re: programmatically drawing an NSImageView in an NSView subclass
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

References: 
 >programmatically drawing an NSImageView in an NSView subclass (From: Benjámin Salánki <email@hidden>)

  • Prev by Date: Re: Controlling NSTextView's ruler accessory view
  • Next by Date: Re: NSPopupButtonCell Oddities
  • Previous by thread: Re: programmatically drawing an NSImageView in an NSView subclass
  • Next by thread: Executing Javascript in webview
  • Index(es):
    • Date
    • Thread