1
votes

This question is for an OSX app, but the same principle can be for iOS.

I have a NSWindowController on storyboard with the following setup.

A. MainWindowController has as subviews:

1) A toolbar with a button

2) A SubVcA viewController with its own content

B. SubVcA has as its content, SubVcB viewController's view

C. SubVcB has a function ButtonPressed

enter image description here

The goal is to trigger the button pressed function in the SubVcB viewController by clicking on the toolbar button.

The way i've been doing it is to have a chain of method implementations from the mainWindowController to the target viewController like so:

MainWindowController call method on SubVcA
-->SubVcA call method on SubVcB
---> SubVcB call method buttonPressed

This works, but it gets messy when the controller stack gets about 4 levels deep. It also gets even more messy, when the SubVC(B) has to send data back up to the MainWindowController, because in-order to have encapsulation (as in not letting the SubVC(B) have too much information about its calling viewControllers), I have to implement delegate methods back up the chain. It gets even messier when you have more than one toolbar button.

Now...I have just started messing around with the firstResponder item on Storyboard

enter image description here

And i realize that it pops up a HUGE list of all methods that are implemented throughout your app with -(IBAction).

So my question now is: In order to reduce method clutter up and down the hierarchy of views, is it good app design to simply hook up the MainWindowController's toolbar button action, directly to the buttonPressed method in the SubVc(B) viewController using the firstResponder object on the storyboard?

Also, are there any other design patters out there that will reduce clutter?

1
This question does not concern the Objective-C language, nor is it about code written in ObjC; please do not add that tag again.jscs
Tags are for categorizing questions by their topic. They complete the sentence "This question is about..." Using them for "exposure" or "this is related to..." makes it harder to find solutions when you're doing a search. Plenty of people watch the [cocoa] and [cocoa-touch] tags in any case.jscs
Seems reasonable. If you have ever done any customisation of your apps menu item you'll see it is done in this way. An alternative approach to avoid this clutter would be to post a notification or use KVO to monitor for changes.Daniel Farrell

1 Answers

2
votes

Using the first responder to allow a nil-targeted action to percolate up the responder chain to whoever can handle it is exactly what the first responder is for. And that is obviously much less messy than you passing the message from hand to hand yourself.