On Jan 7, 2010, at 09:02, Mazen M. Abdel-Rahman wrote: > NSString * defaultSelectionValue = [myDS defaultSelectionValue]; > > NSUInteger defaultSelectionIndex = [myDS comboBox:self > indexOfItemWithStringValue:defaultSelectionValue]; > > [self selectItemAtIndex:defaultSelectionIndex]; > > [self setObjectValue:[myDS comboBox:self > objectValueForItemAtIndex:defaultSelectionIndex]]; > > 'self' is a subclass of NSCombobox. 'myDS' is the datasource - which > contains has information of what the default selection should be (stored in > an NSString). > > In interface builder I bound the value of the NSComboBox to a variable in a > model class. > > My problem is that it seems the model variable is not being properly informed > of the change that is done when the combo box default selection is made - so > that if the user closes the sheet the model variable is still 'nil'. If the > user changes the selection then it works as expected. I tried to addd the > following line when setting the default selection - thinking that maybe I had > to change the NSComboBox value via key value selection: > > [self setValue:[myDS comboBox:self > objectValueForItemAtIndex:defaultSelectionIndex] > forKey:@"value"]; > > but got the following error: > [<AVSComboBox 0x10047b8c0> setValue:forUndefinedKey:]: this class is not key > value coding-compliant for the key value.
There are several possible problems, but not enough information here to figure it out. -- You don't say when/where this code is executed. In 'awakeFromNib'? -- Are you sure this code is executed at all? -- Maybe one of the lines of code returns an unexpected value. Have you verified the results line by line? -- You're using both a data source and a binding. How is that supposed to work? -- If the combo box is *bound* to your model variable (which it shouldn't literally be, but rather bound to a property that's backed by the instance variable), then you should rather set the model variable to the default value. That's kinda the point of bindings -- avoiding glue code like the above. -- Of course your 'setValue:forKey:' failed -- NSComboBox doesn't have a "value" property (though it does have a "value" binding). Its object value property is called "objectValue" as you already know from using 'setObjectValue:'._______________________________________________ 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