Search code examples
objective-cmacoscocoansview

How to disable Click through to a NSView behind another NSView


I have two NSViews on top of each other. One NSView presents a table with rows. On clicking a row another view is shown on top of that view.

Now the problem is when I click on an area on the second view where there is a row on the underneath NSView then it gets clicked. How can I stop that?

Thanks


Solution

  • You can enable touch and mouse events in the top view when it is presented:

    topView.acceptsTouchEvents = YES;
    topView.acceptsFirstMouse = YES;
    

    Edit: the comment is correct that acceptsFirstMouse isn't a property, and must be updated in a subclass.