I've finally got the hang of NSPredicateEditor and custom NSPredicateEditorRowTemplates. (It sure took a while and many, many searches and head-scratchings). However, I am stuck on one thing and I suspect that the problem might lie in the NSPredicateEditor code itself; hence this post.

Here is what I am trying to do:

I have a Core Data document-based application for managing Tasks (to- do items). I am using NSPredicateEditor to manage a set of user- defined Smart Groups. I want the user to be able to build a predicate based on a choice from a popup button. For example the (sub-)predicate might look like this:
    status == "Not Started"

Implementing this is straightforward enough, but I the wrinkle is that want the right hand side of the expression to come from a core data entity. So, no problem, when I create the NSPopUpButton (in my custom NSPredicateEditorRowTemplate class) I simply fill the menuitems from the appropriate array controller, which in turn gets its data from the Core Data entity. After much learning and experimenting, this now works. All is well.

So, then I realize that if (in another window) the user edits the Core Data entity in question, the changes are not reflected in the NSPredicateEditor popup. Okay, this seems like a candidate for cocoa bindings. Again, after much searching and experimentation I come up the following:

NSPopUpButton *rightPopUp = [[NSPopUpButton alloc] initWithFrame:NSZeroRect pullsDown:NO]; [rightPopUp bind:@"content" toObject:arrayController withKeyPath:@"arrangedObjects" options:nil]; [rightPopUp bind:@"contentValues" toObject:arrayController withKeyPath:[NSString stringWithFormat:@"%...@.%@", @"arrangedObjects", [self controllerKeyPath]] options:nil];

where:
- arrayController is the array controller backed by the Core Data entity
- controllerKeyPath is an NSString which holds the keypath for the name of the NSManagedObject (ex. "name")

This works fine in that it fills the NSPopUpButton initially. It even works across the copying that NSPredicateEditor seems to need to make. However, if I change the underlying entity in another window (which uses a different, but identically set up, array controller) the NSPopUpButton menu items do not change. If I close the Smart Groups window and start everything (NSPredicateEditor creation, etc.) all over again, it will pick up the changes in the entity.

Just to make sure that I'm not completely nuts, I put an independent NSPopUpButton elsewhere on the Smart Groups window and bound it (using IB) identically to the NSPopUpButton in the row template. This popup works perfectly: it updates the popup items in real time as expected. I also checked that all the bindings (IB and programatically) are actually being created by using -infoForBinding:NSContentBinding and - infoForBinding:NSContentValuesBinding. Everything appears to be wired up correctly.

I wonder if NSPredicateEditor is somehow blocking the change notifications from the array controller?

Does anyone have any experience trying to bind an NSPopUpButton in a custom NSPredicateEditorRowTemplate?

Oh, in case it matters, I am compiling for GC only.

Thanks for any advice.

Martin


_______________________________________________

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

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

Reply via email to