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

  • SEARCH
  • Home
  • 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 178953
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T14:19:17+00:00 2026-05-11T14:19:17+00:00

I am trying to come to grips with how difficult it is to use

  • 0

I am trying to come to grips with how difficult it is to use NSPopUpButton. It’s by far and away the most difficult user element to program in Cocoa (at least as far as I am finding it).

The use case I have in mind is as follows:

  • I have a class called Port that represents a Serial port.
  • Amongst the attributes is a name field.
  • In the NSPopUpButton I want to display the name field for each port.
  • When a user selects a specific port it is marked in the pop-up with a tick as expected
  • When the user subsequently hits a connect button I can ascertain which of the Ports from the Array was selected.
  • I would like to achieve this using bindings as I think once I get my head around it, it will be the more elegant solution.

Therefore in my AppController.h I am expecting two attributes which I can presumably create as properties and synthesize:

NSMutableArray *allPorts; Port *currentlySelectedPort; 

and one action in my .m:

-(void)didSelectConnect:(id)sender{     NSLog(@'Selected port name is:%@',[currentlySelectedPort name]); } 

in Port.h I have

NSString *name; NSString *baudRate; ... etc ... 

I have created a simple project which contains just a pop up (and a label) and following various articles, I have managed to populate an NSMutableArray with elements which I then use an ArrayController to display values and then on selection set the value of a label (using an object controller). However, as much as this is clever it doesn’t fit the use case I am trying to implement. So I turn here for help

M

  • 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. 2026-05-11T14:19:18+00:00Added an answer on May 11, 2026 at 2:19 pm

    OK, bindings with the NSPopUpButton are a bit complicated because there are two things it needs: a binding for the values, and a binding for which one of those values is selected. What makes it even more complicated is that there are a couple of perfectly legitimate ways of doing that, and which one you choose entirely depends on your program’s structure and, to some extent, personal preferences.

    So, in order to get a list of values, you bind the content property. In your case, you’d probably bind this to the arrangedObjects key of an NSArrayController. In this setup, each menu item represents one object. By default, the title of the menu item is the string returned by calling description on each item in the array. If you want to use a different property for the menu title, you can also bind the contentValues array. Just make sure the key path you specify for contentValues has the key path for content as its prefix (e.g. you might use arrangedObjects for content and arrangedObjects.name for contentValues)

    This will give you menu items that represent objects. What you need next is some way of identifying the selected one. There are three different bindings you can use: selectedIndex, selectedObject and selectedValue. They represent, respectively, the index of the array object that the user selected, the object value (one of the objects in the content array), and the string title of the selected item (one of the objects in the contentValues array if you bound that property).

    So, in your case, you might bind selectedObject to a selectedSerialPort property on your controller class. When the user clicks the ‘Connect’ button, you only have to refer to the selectedSerialPort property.

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

Sidebar

Related Questions

im trying to come up with a design for a wrapper for use when
I am trying to come to grips with using with statements in delphi properly.
Ok, I'm trying to come to grips with this nextSibling function in JS. Here's
I've been playing with javascript recently and I'm trying to come to grips with
I'm trying come up with a method to determine how long after the user
Trying to come up with strategies for finding next prime: Algo #1 (Parallel): private
I'm trying to come up with a way to use a relative stdev range
I am still trying to come to grips with how make an object snap
I'm trying to come up with the code for this question: Ask the user
Having written a few scala tools, I'm trying to come to grips with the

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.