I have a (simplified) Cocoa view hierarchy as follows:
window
- contentView
-- view1
---> button1
--view2
---> textField1
Importantly, the button1
& textField1
do NOT share an immediate superView.
I would like to add a target-action to button1
to perform something (not relevant what precisely) on textField1
(consider textField1
is some custom text field I have created).
In my understanding, the button will have to have a reference to textField1
at initialization so that you can add the "target-action".
My question is what is the best way for button1 to get hold of this reference in a manner that will scale to more complex/deep/nested view hierarchies
I am hopefully looking for something a little more elegant than:
let reference = self.superview.subview[0].subview[0] as NSView
Interface Builder allows you to right-click and drag from the button to the textField to make a 'connection' and it uses some sort of internal ID for this. Is their something similar to be done in code?