Question

I've found a problem in my OSX app that I think is a Mavericks bug.

I have the following hierarchy:

NSView ->NSScrollView ->NSClipView ->NSTableView

When the scroll view doesn't contain any records I'm creating an overlay view as a subview of the NSView, and positioning it above the other subviews. I do this using:

[containerView addSubview:overlay
               positioned:NSWindowAbove
               relativeTo:nil];

FYI, the overlay view is a custom NSView subclass with a drawRect to draw the overlay itself.

On Mountain Lion this works fine, but on Mavericks the overlay does not appear. Googling around I think this is because the overlay is not being positioned above the other sibling views.

I found these links for reference:

Display Order Messed Up

Maverick Issue When Adding Subview on NSView (Stack Overflow)

The second link suggests the following code to fix the issue, which it appears to do, but as I don't have any layer-backed views in my app this feels a bit off:

[overlay setWantsLayer:YES];

Can anyone suggest a workaround for this problem other than the one suggested?

EDIT: I've found that if I put an Xcode breakpoint in the original code (without the workaround) at the point after the subview is added the subviews get added correctly, and my overlay view is displayed. If I remove the breakpoint, the overlay view is no longer displayed. Does this behaviour indicate anything?

Thanks

Darren.

Was it helpful?

Solution

It looks like you've been bitten by overlapping views:

Note: For performance reasons, Cocoa does not enforce clipping among sibling views or guarantee correct invalidation and drawing behavior when sibling views overlap. If you want a view to be drawn in front of another view, you should make the front view a subview (or descendant) of the rear view.

from Apple's Working With A View Heirarchy.

As you note, the common recommendation to fix this is to is to set a layer. However since 10.4 you can hide a view using setHidden:, see Hiding Views in the above reference. This may solve your particular problem as your overlap appears to be total (you don't want to see parts of both views, only one of them).

HTH

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top