setNeedsDisplayInRect not triggering drawRect?
setNeedsDisplayInRect not triggering drawRect?
- Subject: setNeedsDisplayInRect not triggering drawRect?
- From: Michael de Haan <email@hidden>
- Date: Thu, 3 Sep 2009 20:37:31 -0700
I ask with some trepidation, as I am not sure I have done all the
research I can, but I seem to have reached a dead end.
I am simply playing with Hillegass' chapter on Drawing with
NSBezierPath, setting up an NSView with an initial color, then trying
to change a part of that view to a different color.
**Very briefly**
-an NSView control and a button to change a portion of the view
a "model" class (StretchView)
-an iVar : NSColor *currentColor
-an action: changeViewDelta:
The view is initialized thus;
- (id)initWithFrame:(NSRect)frame {
self = [......;
[self setCurrentColor:[NSColor greenColor]];
......
}
and drawRect thus:
- (void)drawRect:(NSRect)dirtyRect {
[[self currentColor]set];
[NSBezierPath fillRect: dirtyRect];
}
This successfully sets the view to a green.
Now the part that does not work.
changeViewDelta as follows:
-(IBAction) changeViewDelta: (id) sender
{
NSRect newBounds;
newBounds.origin.x = newBounds.origin.x + 50.0;
newBounds.origin.y = newBounds.origin.y + 50.0;
newBounds.size.width = 75.0;
newBounds.size.height = 25.0;
[self setCurrentColor:[NSColor blackColor]];
[self setNeedsDisplayInRect:newBounds];
}
The docs, say this:
/*Send a setNeedsDisplayInRect: or setNeedsDisplay: message to the
view. Sending either of these messages marks part or all of the view
as invalid and in need of an update. Cocoa responds by sending a
drawRect: message to your view during the next update cycle.*/
I expected this to call drawRect, but it does not. I had envisioned
that I would trigger drawRect, but clearly there is something I am
missing. ( I had originally set up an outlet (NSView *view, with the
call to it instead of "self" (in setNeedsDisplayInRect:)) but this
does not do it either, and I **think** in this setup, was unnecessary?)
Thanks in advance.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden