Search code examples
objective-ccocoacomboboxnscombobox

NSComboBox - how can I implement a delegate for 2 different comboBoxes?


I've implemented the NSComboBoxDelegate:

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

}

- (void)controlTextDidEndEditing:(NSNotification *)aNotification{

}

- (void)comboBoxWillPopUp:(NSNotification *)notification{

}

- (void)comboBoxWillDismiss:(NSNotification *)notification{
}

but I have 2 comboBoxes - with 2 different functionalities. is there a way to know which comboBox is no on the run, and act accordingly?

or do I have to implement 2 different delegates outside? and if so - is there an easy way to transfer information back to my viewcontroller?

is there a way to get info about the sender of the notification?


Solution

  • For text change (controlTextDidEndEditing, controlTextDidChange...), see the following example.

    - (void)controlTextDidEndEditing:(NSNotification *)obj {
        if ([obj object] == combobox1) {
    
        }
        else if ([obj object] == combobox2) {
    
        }
    }
    

    As for selection change, you need to create IBAction connections for respective objects.