Targeting actions/methods on selected object in NSObjectController
Targeting actions/methods on selected object in NSObjectController
- Subject: Targeting actions/methods on selected object in NSObjectController
- From: Luke Evans <email@hidden>
- Date: Sun, 09 Sep 2012 00:18:54 -0700
I'm not clear on the options for targeting actions on a selected object in bound UI.
I have some list of objects (like a master list), out of which selection allows a single object to show details in UI below. So, this is a pretty standard Master-Detail set up. I have an NSObjectController managing the selected object and a lot of UI binds to properties of this of course in order to display and edit things.
Now one of the properties of this selected object is another list (array) of things, so these area displayed in a table with little "+" and "-" buttons in the popular style.
I need to get the "+" button to fire an action on the selected object managed by the NSObjectController. It would be perhaps regular to have an action defined on the class of these selectable objects such as:
- (IBAction)addListItem:(id)sender
However, I can't see how to target the object inside this NSObjectController in the normal way in xcode (4.4.1 btw). NSObjectController supports a small number of its own actions, and even if it were to somehow pass actions down to the contained object, there's no way I can see to define custom actions on most objects in xcode. Obviously, I could target some other higher-level controller (like a window controller, app controller etc.) that could then have an outlet for the NSObjectController in order to get at its selected object, but that seems like going the long way round and it would create some 'noise' in the form of an extra outlet and actions at that level.
What does seem to work (and is the approach I'm taking now) is the Target binding on the "+" button, bound to the NSObjectController's selection. This works fine, except that I can't easily target action methods, because I can't see how to generate the button's "self" as the Argument binding easily (not without adding another unwanted outlet on a controller just to acquire the button object). So, I currently just target a zero argument method:
- (void)addListItem
So, in a nutshell, what I'm asking is whether there's a nice way to connect to an action method within an NSObjectController from my button action. Perhaps the Target binding _is_ the only way this is supposed to work directly in this sort of scenario?
-- Luke
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden