On 5/7/08 6:16 PM, Dave Dribin said: >In Interface Builder I bind the button's "Enabled" to >"MyController.canEnableButton". The implementation for >canEnableButton is this: > >- (BOOL)canEnableButton { > NSArray * selectedPeople = [peopleController selectedObjects]; > if ([selectedPeople count] < 1) > return NO; > > Person * selectedPerson = [selectedPeople objectAtIndex:0]; > return [selectedPerson.lastName hasPrefix: @"D"]; >} > >Of course, canEnableButton is now dependent on the selection of >NSArrayController. Thus, I added this: > >+ (NSSet *)keyPathsForValuesAffectingCanEnableButton { > return [NSSet setWithObjects: >@"peopleController.selectionIndexes", nil]; >} > >However, this does not trigger the button to update when the selection >changes.
Have you put a breakpoint in 'canEnableButton'? When 'peopleController.selectionIndexes' changes, do you hit the breakpoint? I suspect not. The docs for keyPathsForValuesAffectingValueForKey say keyPaths are ok, but mmalc has mentioned on this list "provided that the path doesn't include to-many relationships". This appears to be true in your case, so probably explains it. The docs don't mention this caveat. :( However, I haven't got keypaths to trigger even with to-one relationships, which I have been meaning to investigate... >In observeValueForKeyPath:ofObject:change:context: > > if (context == SelectionIndexesContext) > { > [self willChangeValueForKey:@"canEnableButton"]; > [self didChangeValueForKey:@"canEnableButton"]; > } > >This works, however, it just seems wrong to use {will/ >did}ChangeValueForKey: like this. Also, I seem to remember reading that doing willChange/didChange back-to- back without actually changing anything is a no-no. You might check the archives to confirm my shoddy memory. -- ____________________________________________________________ Sean McBride, B. Eng [EMAIL PROTECTED] Rogue Research www.rogue-research.com Mac Software Developer Montréal, Québec, Canada _______________________________________________ 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 [EMAIL PROTECTED]