Re: monitoring changes in a local property
Re: monitoring changes in a local property
- Subject: Re: monitoring changes in a local property
- From: Quincey Morris <email@hidden>
- Date: Wed, 09 May 2012 19:12:29 -0700
On May 9, 2012, at 18:48 , Koen van der Drift wrote:
> Hmmm, an indexset just gives me an index, how do I get the object from it that it belongs to? I think I still need to be able to access the NSArrayController (that feeds the NSTableView) for that?
The array controller is also bound to some indexed property of your app delegate, "myThings". For example, you might have (in the app delegate .h file):
@property (readonly) NSArray* myThings;
Then to get the selected objects:
[appDelegate.myThings objectsAtIndexes: appDelegate.selectionIndexes];
or to get just "the" selected object:
appDelegate.selectionIndexes.count ? [appDelegate.myThings objectAtIndex: appDelegate.selectionIndexes.firstIndex] : nil;
Note that what you're doing here is querying the MVC "M" (model) for objects. Getting the selected objects from the array controller is (IMO) querying the "V" -- because I think of array controllers as effectively part of the view complex: they are, after all, typically part of the NIB that defines the view components. Technically, they're controllers (mediating controllers, rather than coordinating controllers), but my attitude is that they're [semi-]private to a sub-MVC system within the main MVC "V". Others might not choose to think of them this way.
Anyway, my point is that by querying the "M" rather than the "V", your view controller doesn't have dependencies on "V" implementation details. It doesn't need to know that there is a table view or an array controller. That's *usually* a cleaner design.
(Sometimes it *is* easiest to query the array controller directly -- for example, if you need "selectedObjects" or "arrangedObjects" in the sorted order.)
_______________________________________________
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