Search code examples
swiftmacoscocoanstableviewnsoutlineview

NSTextField in an NSOutlineView doesn't send its action


I have a view-based NSOutlineView that I use as a sidebar.

I load each sidebar widget by instantiating a view controller from a storyboard, then setting the cell's view to that of the view controller.

At first I couldn't even focus the text field, but found out I had to subclass the outline view and return true for validateProposedFirstResponder

I can't get any action out of the text field. Here's what I tried

  • IBAction. Never called.
  • Setting the view controller as the delegate for the text field. Never called.
  • Setting the text view's outlet's action and target directly (target = self, action = a selector to and objc function). Never called.

I suspect it's the Outline view that is blocking my "text editing finished" action? How can I make my text field tell the View Controller that it has been edited?

I am able to read the value of the text field through its IBOutlet, so the connection works.

I also noted that upon hitting Enter in the text field, it immediately loses focus. This was not the behavior outside the outline view.


Solution

  • I had to add the instantiated view controller to the presenting view controller. Just presenting the instantiated view controller's view in the outline view was not enough.