> On 9 Mar 2017, at 18:32, corbin dunn <corb...@apple.com> wrote: > >> >> On Mar 8, 2017, at 8:46 AM, Jeremy Hughes <moon.rab...@virginmedia.com> >> wrote: >> >> If needsDisplay is set to true for an NSView, does that also cause subviews >> to be redrawn? >> >> I’ve seen conflicting statements about this, but haven’t found anything in >> Apple’s documentation. > > Just to be clear: if you want a view to be redrawn you should call > setNeedsDisplay on that view. That’s really the bottom line. There are some > cases where AppKit will redraw subviews when a parent view is invalidated, > but you should not depend on this!
Thanks for being clear! > I also don’t recommend things like this: > >> override var needsDisplay: Bool >> { >> willSet >> { >> for view in subviews >> { >> view.needsDisplay = newValue >> } >> } > > > Instead, it is better if your subviews invalidate themselves when their state > changes. In this case I have a view that is broken up into subviews but should really be treated as a single view as far as redraws are concerned. When the model object for the view changes, the entire view needs to be redrawn. The controller for this view is not aware of each individual subview or what kind of view it is dealing with - it’s actually dealing with a more general view that is a superclass of different kinds of specific views. Also, the views aren’t aware of model states, so they can’t invalidate themselves. The willSet override isn’t a general override that will cause all views to redraw whenever a superview is redrawn. It’s a specific override for a particular view that is really a cluster of subviews and which needs all of its subviews to be redrawn whenever it is invalidated. Jeremy _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com