On Aug 31, 2008, at 6:38 PM, Jamie Phelps wrote:

I have an NSPopUpButton with five menu items: WTD, MTD, QTD, YTD, and Specific Dates. What I want to do is show and hide two labels and textfields for Start Date and End Date depending on if the Specific Dates option is selected.

My first attempt was to do

@property (readonly) BOOL specifyingDateRange;

-(BOOL)specifyingDateRange{
   if([dateRangePopUp indexOfSelectedItem] == 4){
       return YES;
   }
   return NO;
}

but this is not working correctly.

Can anyone explain what the correct implementation is and possibly what mistake I made in assessing the problem?

It's hard to know without more details.

My suspicion is that you haven't arranged for any KVO change notification to be sent out when this property changes its value. KVO and Bindings do not poll the properties of objects to check if they've changed. There has to be an affirmative notification sent out to observers telling them that the property may have changed. That notification is triggered by a message to the object which has the property -- either a KVO-compliant setter (preferred) or a pair of willChange…/didChange… messages (last resort if your design absolutely can't conform to the normal way of doing things).

I assume the above method is in your controller. It certainly shouldn't be in the model. However, is the mode implied by the pop-up expressed in the model? And is the pop-up's selection bound through the controller to that model property? If so, then I'd recode that method to depend on the model property instead of the pop-up view's state. And then I'd use a +keyPathsForValuesAffectingSpecifyingDateRange method to inform KVO that when the model property changes, that implies a change in the specifyingDateRange property of the controller.

If somehow the mode implied by the pop-up isn't a model property, then I'd make it a controller property. You'd still bind the pop-up's selection to it, and you'd still use +keyPathsForValuesAffectingSpecifyingDateRange to inform the KVO system that the two properties are interrelated.

Cheers,
Ken_______________________________________________

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]

Reply via email to