我有一个 NSComboBox。我已经设置了一个动作选择器。当盒子被隐藏时,选择器会触发,即使用户从未接触过它。是的,我需要隐藏它。
IBOutlet NSComboBox *comboBox;
[comboBox setAction:@selector(onComboBoxSelection:)];
- (void)onComboBoxSelection:(id)sender
{
NSLog(@"Why does this fire twice");
//My code doesn't actually set hidden here, it's just for proof while debugging the issue.
[comboBox setHidden:YES];
}
为什么隐藏 NSControl 会触发它的选择器?修复它的最佳方法是什么?
更新: 我已经通过包装方法来修复它。但我仍然想了解原因或其他解决方法。
- (void)onComboBoxSelection:(id)sender
{
if(![sender isHidden]{
NSLog(@"Now only fires once");
//My code doesn't actually set hidden here, it's just for proof while debugging the issue.
[comboBox setHidden:YES];
}
}