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 7563347
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T13:38:39+00:00 2026-05-30T13:38:39+00:00

I’m moving on from iOS to Cocoa and trying to muddle through my first

  • 0

I’m moving on from iOS to Cocoa and trying to muddle through my first few programs. I thought it would be simple to add an NSComboBox to my form, well that part was. I added <NSComboBoxDelegate, NSComboBoxDataSource> to my interface, two data callbacks, and the notifier:

@interface spcAppDelegate : NSObject <NSApplicationDelegate,
                      NSComboBoxDelegate, NSComboBoxDataSource>

- (id)comboBox:(NSComboBox *)aComboBox objectValueForItemAtIndex:(NSInteger)index;
- (NSInteger)numberOfItemsInComboBox:(NSComboBox *)aComboBox;

- (void)comboBoxSelectionDidChange:(NSNotification *)notification;

@end

I control dragged the combobox to the app delegate (which is the only class in my simple default app) and wired up the delegate and data source but none of those events fire. I thought app delegate was correct but since it didn’t fire, I also tried “file owner” and “application”. I didn’t think those would work and they didn’t.

Whats the right way to wire up the delegate/data source for an NSComboBox in a Cocoa app?

Thanks!

  • 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-30T13:38:40+00:00Added an answer on May 30, 2026 at 1:38 pm

    Provided you’ve actually implemented those methods in your spcAppDelegate.m file, you may want to double-check that Uses Data Source is checked for the NSComboBox in the nib file in Interface Builder:

    enter image description here

    Note that it wasn’t set by default in a quick test project I created. Running without that checkbox set should log the following to console when you launch the app:

    NSComboBox[2236:403] *** -[NSComboBox setDataSource:] should not be called when
              usesDataSource is set to NO
    NSComboBox[2236:403] *** -[NSComboBoxCell setDataSource:] should not be called 
                 when usesDataSource is set to NO
    

    While the NSComboBox Class Reference is somewhat helpful, when I was first learning, I found that if there were companion guides linked to for a class, those were much more helpful in understanding how one should use the class in practice. If you look at the top of the NSComboBox class reference at the Companion Guide, you’ll see Combo Box Programming Topics.

    To set up a combo box that uses a data source, you could use something like the following:

    spcAppDelegate.h:

    #import <Cocoa/Cocoa.h>
    
    @interface spcAppDelegate : NSObject <NSApplicationDelegate,
                      NSComboBoxDelegate, NSComboBoxDataSource> {
        IBOutlet NSWindow            *window;
        IBOutlet NSComboBox            *comboBox;
        NSMutableArray                *comboBoxItems;
    }
    
    @property (assign) IBOutlet NSWindow *window;
    
    @end
    

    spcAppDelegate.m:

    #import "spcAppDelegate.h"
    @implementation spcAppDelegate
    @synthesize window;
    - (id)init {
        if ((self = [super init])) {
            comboBoxItems = [[NSMutableArray alloc] initWithArray:
                   [@"Cocoa Programming setting the delegate"
                                            componentsSeparatedByString:@" "]];
        }
        return self;
    }
    - (void)dealloc {
        [comboBoxItems release];
        [super dealloc];
    }
    - (NSInteger)numberOfItemsInComboBox:(NSComboBox *)aComboBox {
        return [comboBoxItems count];
    }
    - (id)comboBox:(NSComboBox *)aComboBox objectValueForItemAtIndex:(NSInteger)index {
        if (aComboBox == comboBox) {
            return [comboBoxItems objectAtIndex:index];
        }
        return nil;
    }
    - (void)comboBoxSelectionDidChange:(NSNotification *)notification {
        NSLog(@"[%@ %@] value == %@", NSStringFromClass([self class]),
          NSStringFromSelector(_cmd), [comboBoxItems objectAtIndex:
            [(NSComboBox *)[notification object] indexOfSelectedItem]]);
    
    }
    @end
    

    Sample Project: http://github.com/NSGod/NSComboBox.

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

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to loop through a bunch of documents I have to put
I'm making a simple page using Google Maps API 3. My first. One marker
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

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.