> On Jan 2, 2018, at 12:18 AM, Motti Shneor <motti.shn...@me.com> wrote: > > Hi Keary, and many thanks for the answer. > > The Main / Document window in my application is a master-detail, and there I > have it working as desired. > > An NSPopupButton placed in the Detail view is set up using same bindings (to > different entities and relations). It correctly shows the value for the > selection in the source-list. It will keep displaying a value (not the > multiple-values placeholder) if the values for all selected rows are the same. > > So no - the NSArrayController is not agnostic about the values, and the > binding attribute says "Multiple values placeholder” - not multiple Selection > or Object Placeholder. I can’t understand why it won’t work in the other > window. In both places I am not using the contentArrayForMultipleSelection > but I’ll read about this as well.
Your reasoning is good, although I have to say how bindings work doesn’t always seem to stand to reason ;-) Anyway, I stand corrected. >> 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… > > > I was originally thinking I could make this work in the table, by showing a > check-mark state in the pop-up menu for every species that appears in the > selection, and so make behavior indifferent to which-row-in-the-selection was > clicked. I was lead to think this remembering there is actually but one > NSCell instance per column anyway… Obviously it doesn’t work for me (I am > still curious why). > > I agree that this may be confusing interface - but this is a simple window > with just slim header and footer, and a single table end-to-end. There was no > “detail” part for me. > > I did try to place a Popup-button outside of the table (master-detail style) > as you suggested, for experimenting, (as I have it working in other place). > Here changes do apply to the whole selection - but the > multiple-values-placeholder shows “Multiple species selected” even when all > selected rows have the same value. There is certainly two clues here, as I would now expect. First, that the table editing system is somehow interfering. Second, that NSArrayController or the binding system (whichever is responsible) is not seeing equality between values that seem equal to you. If you can solve the latter issue outside of table editing, you may be able to solve inside of table editing. > If I last elect to add such out-of-table popup - can you think of a decent > way to disable opening those in-table popup button cells when more than one > line is selected? If you choose this route I think a better UI is to change the in-table popup bindings to apply to only the specific row. I wouldn’t disable the popup in this case as it will always behave as expected, and disabling would seem to be an odd UI to me. >> >>> 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. > > Bindings are two-way KVO / KVC. In KVO you usually register for > “willChangeValueForKey” or in the ObserveValueForKeyPath you can register for > NSKeyValueObservingOptionPrior or at the very least, look at the change > dictionary, and see both the old and new values. Isn’t there a way to > register to these bindings KVO cycle? Looking at your issue more closely, there are two things you want to accomplish: 1. Reject an incompatible value. You can do this with key-value validation, which is your best choice IMHO 2. Re-calculate dependent values in the model. This can be done with simple observation, after-the-fact. If you need to do these calculations to determine whether the “species” value is valid, you can combine the two (i..e calculate in the validation method) and only make property changes when the “species” value is valid. > Ah… any guesses WHAT is wrong there? are there any details I forgot? I tried > to add screenshots of the project but messages here are limited in size. I think the issue with the table is either that you are hitting an edge case of the bindings implementation or that they aren’t designed to work the way you want. I don’t think there is a way around that—I think the only solutions will likely be outside of the bindings system itself. >>> 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. > > Well - this I was able to do now - but with one strange behavior. I added the > -(BOOL) validateMenuItem:(NSMenuItem *)menuItem to my Window controller, and > it IS called for each and every item in the popup buttons - both in the > NSTableView and outside it. The problem is - how to identify these items in > the method. For other menus in my app - I use tags. but these popup-button > menus are populated by binding in runtime. I tried to identify them using > IBOutlet - pointers to the menus in the .xib, but strangely - the in-table > menu in runtime is not the same as the one in the IBOutlet. It looks like the > NSPopupButtonCell is duplicating the original menu, and populates the copy. Interesting on menu validation, though I would expect what you are seeing and I agree with your conclusions. Every popup cell in a table column must be a different object. Did you check to see whether the -representedObject of the NSMenuItem is being set? I don’t recall whether bindings does this, but if it does, you can use its unique ID (if you have a developer-specified ID) or have the tag be a property on the entity. If you can know that the menu title is always unique you can always test on that. 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