Search code examples
swiftmacoscocoanssplitview

Get Child with Focus inside NSSplitView


I have an NSSplitViewController which has two child view controllers. I have a menu action that is passed to the split view controller and I want to be able to send the action triggered by the menu to the appropriate child controller.

For example if I had one list on either side of the split, I would want a delete menu action to be passed to the one the user is focussed on.

I don't really want to implement remembering which child is focussed myself, if I can avoid it.


Solution

  • @Willeke was right - connecting first responders up makes it work.

    Both view controllers (each child of the split view) need to implement some method that will get called - in my case deleteItems:. The delete action in the menu then links to the first responder with name deleteItems:.

    The method will be called on the active view controller when the menu is selected.