Re: DotView.m
Re: DotView.m
- Subject: Re: DotView.m
- From: "Erik M. Buck" <email@hidden>
- Date: Wed, 7 Nov 2001 11:01:27 -0600
>
Is the [self setNeedsDisplay:YES] message firing the -(void)drawRect:
>
(NSRect)rect? I know this is not good MVC but couldn't DotView.m replace
>
[self setNeedsDisplay:YES] with [self drawRect: (NSRect)frame?
Do not call -drawRect: directly. Call -display or setNeedsDisplay: or one
of their variants.
If you read the copious documentation on NSView you will see that
setNeedsDisplay:YES simply marks the view as needing display at some time in
the future when it is convenient for the appkit to display it (like before
the next event).
- (void)setNeedsDisplay:(BOOL)flag
If flag is YES, marks the receiver's entire bounds as needing display; if
flag is NO, marks it as not needing display. Whenever the data or state used
for drawing a view object changes, the view should be sent a
setNeedsDisplay: message. NSViews marked as needing display are
automatically redisplayed on each pass through the application's event loop.
(View objects that need to redisplay before the event loop comes around can
of course immediately be sent the appropriate display... method.)
See Also: - setNeedsDisplayInRect: - needsDisplay
>
>
And, on page 136 I quote, "2. Implement dealloc as shown. There's nothing
>
unusual here:"
>
>
-(void)dealloc{
>
[color release]
>
[super dealloc]
>
}
>
>
I know Learning Cocoa is not a master's thesis, but the part about
"nothing
>
unusual here" is a tutorial that abandons the reader. My question is when
>
the DotView.m is loaded into memory, it eventually has to be unloaded,
this
>
is the purpose of the above, but what is firing this method? Please tell
me
>
what is not unusual.
>
Read Object Oriented Programming and Objective-C. Correct implementation
of -dealloc is the absolute most basic aspect of Cocoa programming in
Objective-C. There is nothing unusual about the implementation of -dealloc.
By the time any book is discussing how to subclass NSView, it is way too
late to be talking about how to implement -dealloc. No book can review every
topic in every chapter. I suggest you start over reading the book or
reference some more introductory tutorials that use Objective-C.
-dealloc is called automatically when an object's reference count reaches
zero. Do not call -dealloc directly except to call the super class
implementation from within a -dealloc implementation.
References: | |
| >DotView.m (From: Craig Bakalian <email@hidden>) |