I am building a document based application that uses a split view controller that contains a custom NSViewController on the left and a custom SKView controller on the right. The left view controller has a button that when pressed creates a modal window that has text fields for entering values as well as 'OK' and 'Cancel' buttons.
All of that works in so far as the modal window popping up goes, but when the 'OK' button is pressed I want to access contents of the dialog's text fields from within my custom SKViewController. This is problematic, because the SKViewController is in a differnt scene from the dialog window or even the NSVIew contoller on the left of the split view. So there is no way to just connect to IBActions on the SKView controller or connect up IBOutlets to the dialogs text fields.
Approaches I have tried:
- Using NSNotificationCenter to send a message when the 'OK' button is pressed. This message is received by my SKView controller. This approach works, but has one big flaw - every open document SKViewController gets the message and tries to act on it. I could probably figure out some way to target the message with an identifer so only the proper SKViewController processes the message, but this seems like it's not the best practice.
- Sending an action to the first responder to call a function on my SKViewController. This seems like it's probably along the lines of the correct way to handle this, but it hasn't worked for me, probably because the the SKViewController is not in the responder chain when the dialog is modal.
A third approach I am considering is to set the NSView that launches the modal a delegate of the modal, so the modal can call an action on the NSView. The NSView will in turn have a delegate of the NSSplitPaneViewController, which will have an action to call the desired method on the SKViewController. So the message bounces up to the split view controller then back down to the SKViewController. But this level of coupling seems pretty bad.
So, what is the best approach to pass modal dialog results to an aritrary view?