开发者

How to differentiate different comboboxes delegated to one comboBoxSelectionDidChange:

开发者 https://www.devze.com 2023-02-01 12:43 出处:网络
Can I delegate t开发者_开发百科wo NSComboBoxes to one comboBoxSelectionDidChange: method and run an if statement to differentiate between the two boxes?I believe this may be a case where you can use N

Can I delegate t开发者_开发百科wo NSComboBoxes to one comboBoxSelectionDidChange: method and run an if statement to differentiate between the two boxes?


I believe this may be a case where you can use NSNotification's object method to obtain a pointer to the combo box that triggered the notification.

For example:

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
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消