• 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: Panning a View
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Panning a View


  • Subject: Re: Panning a View
  • From: "I. Savant" <email@hidden>
  • Date: Tue, 28 Jul 2009 14:05:54 -0400

On Jul 28, 2009, at 1:56 PM, Kyle Sluder wrote:

No, you must not do this.

...
So why would you think to do it in -drawRect:?  Do it in
-awakeFromNib, or -[NSWindowController windowDidLoad], or -[NSDocument
windowControllerDidLoadNib:].  These are the places to do post-nib
loading setup.

It might be more helpful to explain why this isn't a good idea ...

  Several things to consider:

1 - The -drawRect: method is supposed to be kept as lightweight as possible because it could be called many times.

2 - What happens if something else causes your view's frame to be set (which may cause the system to call -drawRect:, which may call your frame setter, which calls -drawRect:...)?
)


... those are off the top of my head but aren't necessarily "must nots", just "probably shouldn'ts". Leopard introduced -(void) viewWillDraw for last-minute adjustments. If handled correctly, performance may not be an issue at all and cycles can be avoided.

It's better, though, to implement a -sizeToFit method and call it once when the view is created (or it's given its contents to display). That's just better design.

If I'm missing something that's an absolute "must not", Kyle, I welcome the insight.

--
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:
This email sent to email@hidden


References: 
 >Panning a View (From: David Blanton <email@hidden>)
 >Re: Panning a View (From: David Blanton <email@hidden>)
 >Re: Panning a View (From: Graham Cox <email@hidden>)
 >Re: Panning a View (From: David Blanton <email@hidden>)
 >Re: Panning a View (From: Kyle Sluder <email@hidden>)
 >Re: Panning a View (From: David Blanton <email@hidden>)
 >Re: Panning a View (From: Kyle Sluder <email@hidden>)

  • Prev by Date: Re: NSWindow reference remains null after window did load
  • Next by Date: Re: NSWindow reference remains null after window did load
  • Previous by thread: Re: Panning a View
  • Next by thread: Re: Panning a View
  • Index(es):
    • Date
    • Thread