Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 904023
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T15:58:58+00:00 2026-05-15T15:58:58+00:00

I have several NSComboBoxes created in Interface Builder, and one created programmatically. The NSComboBoxes

  • 0

I have several NSComboBoxes created in Interface Builder, and one created programmatically.

The NSComboBoxes created in Interface Builder are perfect. I have their Value bound to the Shared User Default Controller, and when their view is opened they are sitting there with the correct value. Importantly, this value is shown as “normal” text in the NSComboBox. In other words, the value doesn’t appear selected. This is what I want.

For the NSComboBox that is created programmatically, I set the value using selectItemAtIndex:0. When I do this, the correct item is selected–but the text appears selected. I.e., it is highlighted and everything. I don’t want this. Here are the workarounds I’ve attempted:

(i) Get the field editor and set insertion point to the end of the text. This doesn’t work although, oddly, the field editor’s string is either nil or empty when doing this. I’m not sure if this is correct behavior for the field editor.

(ii) Trying various other ways of setting the combo box’s value, such as setObjectValue, takeStringValueFrom, etc.

(iii) Finally, and most frustratingly, I tried to set the value of the NSComboBox using [myComboBox setValue:@”The Default Item” forKey:@”value”]; This fails with objc_exception_throw, presumably because there is no such KVC key. But I know that the value of the combo box can be set by KVO, because it works in interface builder! I’m guessing that I don’t know the correct key path. I tried to enumerate all the properties using introspection, but I can’t get the code working right (objc_property_t isn’t in the expected headers).

So, I have two questions:

First, does anyone know how to set a default value for NSComboBox programmatically, so that the text in the box isn’t selected? I will go to any lengths to do this, including a new NSComboBoxCell subclass, if it comes to that.

Second, can somebody tell me what key or key path IB is using to set the value of an NSComboBox? Or alternatively, why my efforts to do this are failing?

I’ve been working on this for many hours now and I am truly disspirited!


THANK YOU, mustISignUp! So nice to have this fixed. A little bit of followup:

(i) Selection of the text is definitely caused by focus. Calling setRefusesFirstResponder:YES fixes the problem. Unfortunately, the window really wants to focus on this combo box, as setting refusesFirstResponder back to NO (later, after window inititation) causes text selection again (I do want the user to be able to focus on this box if he desires). Therefore, in my case, the definitive solution was to call [window makeFirstResponder:otherControl]. Oddly, though [window makeFirstResponder:nil] doesn’t work. Any ideas why?

(ii) Thanks for pointing out the difference between bindings and properties. I learned a lot while looking into this question. For one, I learned that you can get a list of bindings by calling – (NSArray *)exposedBindings, which for NSComboBox returns (fontSize, alignment, toolTip, fontName, enabled, contentValues, fontFamilyName, font, hidden, fontItalic, textColor, value, content, editable, fontBold). Second, I was able to set the value using [myComboBox bind:@”value” toObject:[NSMutableString stringWithString:@”defaultValue”] withKeyPath:@”string” options:nil], where NSMutableString has a category on it that turns “string” into a property. Finally, this actually doesn’t fix the text selection “problem”. The difference between text selection with this combo box and those in Interface Builder must be their position in the window…I guess that this combo box is just slated to become initialFirstResponder while the others weren’t.

So my only remaining question might be why [window makeFirstResponder:nil] doesn’t work to take focus off the combo box. Not super-important, but I’d be curious if anybody has an idea.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T15:58:58+00:00Added an answer on May 15, 2026 at 3:58 pm

    Firstly, i think the text is selected because calling selectItemAtIndex: has made the comboBox the firstResponder. You could use setRefusesFirstResponder:YES or you could make another item the first responder to make the text not appear selected.

    If i have understood correctly and you want to change the selection of the comboBox you are doing it the right way.

    Secondly, you are confusing Bindings and KVC. NSComboBox has a binding called ‘value’, not a property called ‘value’. It is meaningless to try to set it with setValue:forKey:, and Interface Builder definitely isn’t doing this.

    You would be right in thinking this is un-obvious and confusing and maybe better names could have been chosen for the bindings.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 453k
  • Answers 453k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The reference is stored in the Visual Studio solution file.… May 15, 2026 at 9:22 pm
  • Editorial Team
    Editorial Team added an answer I think it's not possible. During the integration, the branch… May 15, 2026 at 9:22 pm
  • Editorial Team
    Editorial Team added an answer One solution would be to decode the entities into the… May 15, 2026 at 9:22 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.