Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How Can I Notify DrawRect Method?



On Tue, Dec 9, 2008 at 11:17 AM, Chunk 1978 <email@hidden> wrote:
> that works... but now i want that rect to redraw itself when notified
> to do so, but i can't figure out how to notify the NSRect to draw
> again... all my NSUserDefaults colorAsData is in place, as well as my
> NSNotifications.  it will print to NSLog so i know that notification
> is being called, but how do direct that notification to the drawRect
> method?

  In addition to NIck's advice, you should give this a thorough read
(to save yourself lots of headaches):

http://developer.apple.com/DOCUMENTATION/Cocoa/Conceptual/CocoaDrawingGuide/Introduction/chapter_1_section_1.html

  Also, the custom view that draws the rectangle should probably
maintain this property itself (such as -rectColor). It's probably
trivial for your current application (which looks like a learning
exercise) but has performance implications in a full-fledged app. This
way, you can always use [self rectColor] instead of all the messaging
overhead of asking preferences each time you draw.

  To handle the color change in the user defaults, use the same method
(the notification) but set the new color as the notification's object
when you post the notification in the first place, then your view can
ask the notification for its -object and (if it's a proper color),
call [self setRectColor:[aNotification object]].

  In your -setRectColor: you can store the color then immediately call
[self setNeedsDisplay:YES] (if the color is different). This way, any
time the view's color is set (either directly or by notification), the
view is always marked as needing display and no further calls to
-setNeedsDisplay: are needed for rect color changes. That means less
to debug. :-)

--
I.S.
_______________________________________________

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:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden

References: 
 >How Can I Notify DrawRect Method? (From: "Chunk 1978" <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.