NSComboBox - item selected action?

1.8k views Asked by At

is there an IBAction for item selection in NSComboBox?

I trying to define 2 different actions - one for item selected from the drop box, and another action for entering a new value. is that possible?

*I'm doing a mac app, not iOS

2

There are 2 answers

0
sbooth On BEST ANSWER

I believe you can distinguish between the two events in your delegate, but not through an IBAction. The NSComboBoxDelegate protocol responds to the selector - (void)comboBoxSelectionDidChange:(NSNotification *)notification. You can use this to determine when an item was selected from the drop box, and use the text editing delegate selector - (void)controlTextDidEndEditing:(NSNotification *)aNotification to determine when the user entered text directly.

0
Aviram Netanel On

so I added this code to my viewController.m:

-(void)comboBoxSelectionDidChange:(NSNotification *)notification{
    NSLog(@"comboBoxSelectionDidChange");
}

- (void)controlTextDidEndEditing:(NSNotification *)aNotification{
     NSLog(@"controlTextDidEndEditing");
}

Then, connected my combobox "cmbbox" to the delegate on viewDidLoad:

- (void)viewDidLoad {
      [super viewDidLoad];
      self.cmbbox.delegate = self;
}

and finally, added the NSComboBoxDelegate delegate protocol to viewController.h header file:

@interface ViewController : NSViewController <NSComboBoxDelegate>