Your example is difficult to follow. You may need to post the actual project or 
a similar project online to get helpful feedback.

From the documentation: "NSArrayController is a bindings compatible class that 
manages a collection of objects. Typically the collection is an array, however, 
if the controller manages a relationship of a managed object the collection may 
be a set.” If what you are trying to do falls within the scope of this 
statement it should work correctly, if not it won’t.

NSArrayController will not manage a Core Data relationship. It manages a single 
collection of objects which may be an array or in the case of a Core Data 
relationship a set of objects. This single collection may be sorted, filtered 
and members of the collection may be selected. You can also set the class of 
objects that make up the content and then add and remove objects of that type 
to and from the collection.

So NSArrayController works within a very narrow range of capabilities.

--Richard Charles

> On Jan 1, 2018, at 2:46 AM, Motti Shneor <motti.shn...@me.com> wrote:
> 
> Hello everyone. Please excuse the anachronism, I am maintaining an old Mac 
> Application written early 2014 when Swift was not an option.  Pure Obj-C, 
> CoreData, and “No-custom-UI” approach.
> 
> I have an NSCell based NSTableView, whose columns are bound to an 
> NSArrayController, whose Content-Array in turn is bound to some CoreData 
> to-many relation - thus the table shows all the related entities.
> 
> Say we have a “WaterSample” entity, and the to-many relation is called 
> “measurements” and each Measurement has length, width, depth, colony-size and 
> species properties - each bound to one of the NSTableColumns. So far - the 
> very basic and stranded use of binding.
> 
> Of the Measurement properties - the species - is yet another to-one relation 
> to the  “Species” table. To allow the user to edit/change the species of a 
> Measurement (line in the table) I have placed a Popup Button Cell in the 
> “Species” column, and bound it like this:
> 
> Content  bound to Species Array Controller, Controller Key: arrangedObjects, 
> Content Placement Tag: 0
> Content Values  bound to Species Array Controller, Controller Key: 
> arrangedObjects, Model Key Path: codeAndName, Content Placement Tag: 0,  
> Multiple Values Placeholder: Multiple Species
> Selected Object  bound to Measurements Array Controller, Controller Key: 
> arrangedObjects, Model Key Path: species, Allows Editing Multiple Values 
> Selection, Conditionally Sets Enabled, Creates Sort Descriptor
> 
> Now it SEEMS to KIND-OF work, (I see the species codes and names, user can 
> click the popup button on each row to see and select from all our Species, 
> and even change the species to another one.
> 
> But I have these issues:
> 
> 1. When I select several Measurement rows of the table — All with the same 
> Species— and click the popup button on any row - it shows “Multiple Species” 
> as the selected value - although all rows have the same species selected.
> 
> 2. Selecting a species only applies to the row where I clicked the popup 
> button - not to all selected rows. After releasing the mouse the selection 
> reduces to just one row - but it is terribly confusing.
> 
> 3. The editing is immediate, via binding, and I did not find any place to 
> interfere (Say I need to re-calculate things as species changed, or even 
> prevent the change if the newly-selected  species is not compatible with the 
> original.
> 
> I have set up a menu Action to the popup-button-cell - and it is called - but 
> the change is already done in the model.
> 
> My questions: 
> Is there anything wrong in my binding settings?
> When the content of a popup-button-cell is populated by binding - Can I still 
> apply NSMenu Validation protocol to that menu, and Filter/Enable/Disable menu 
> items as user clicks to open the menu?
> When the editing is done via the “Selected Object” binding - can I still 
> somehow intervene and “Catch” the change in code before it happens?
> 
> Any hint will be appreciated - and - Happy new year everyone.
> 
> 
> Motti Shneor
> ---
> ceterum censeo microsoftiem delendam esse
> ---

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to