• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: binding NSComboBox default selection
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: binding NSComboBox default selection


  • Subject: Re: binding NSComboBox default selection
  • From: Quincey Morris <email@hidden>
  • Date: Thu, 7 Jan 2010 12:16:51 -0800

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 (email@hidden)

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:

This email sent to email@hidden

References: 
 >binding NSComboBox default selection (From: "Mazen M. Abdel-Rahman" <email@hidden>)

  • Prev by Date: Re: A password strength checker
  • Next by Date: Drawing A Mutable String
  • Previous by thread: binding NSComboBox default selection
  • Next by thread: Re: binding NSComboBox default selection
  • Index(es):
    • Date
    • Thread