How to distinguish different combobox delegated to one comboBoxSelectionDidChange:

Is it possible to delegate two NSComboBoxes to one comboBoxSelectionDidChange: method and run an if statement to distinguish between two fields?

+3
source share
1 answer

I believe this may be the case when you can use the object method NSNotificationto get a pointer to the combo box that caused the notification.

For instance:

Assuming you have something like this in your .h file:

@interface MDAppController : NSObject {
    IBOutlet NSComboBox   *comboBox1;
    IBOutlet NSComboBox   *comboBox2;
} 

@end

In your .m file:

- (void)comboBoxSelectionDidChange:(NSNotification *)notification {
    NSComboBox *comboBox = (NSComboBox *)[notification object];
    if (comboBox == comboBox1) {
        // do something
    } else if (comboBox == comboBox2) {
        // do something else
    }
}
+5
source

Source: https://habr.com/ru/post/1781869/


All Articles