> 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.
My understanding (which could be wrong) is that this would be expected behavior. I.e., NSArrayController is agnostic about the actual values so either displays the single value or the placeholder if multiple values are selected, regardless of whether they are the same. I don’t think there is a non-hacky way to accomplish what you want, but you can play around with the contentArrayForMultipleSelection binding to see if you can get close. > 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. I suspect that you are running afoul of trying to use bindings in a way that they are not intended. Editing multiple values is designed to be used in a master-detail type interface, and you are combining that with in-table editing. To verify this, have a single popup outside of the table with the same bindings except selected object to array controller->selection and see if you get the behavior you prefer. I would say that the UI you are trying to create is rather 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. You cannot intercept bindings, except to do validation, so whatever you do must be after-the-fact. > 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? Probably, see my inline response above. > 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? I would say, generally, no, as you either have to set the delegate of the menu or action of each item. The former you might be able to do with a table delegate method, but you may not be able to do the latter depending on when bindings populates the popup. > When the editing is done via the “Selected Object” binding - can I still > somehow intervene and “Catch” the change in code before it happens? See above. HTH, Keary Suska Esoteritech, Inc. "Demystifying technology for your home or business" _______________________________________________ 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