我有一个包含许多商店和 NSSearchfield 的 View ,如果用户在搜索字段中按向上箭头,我想对商店做一些有趣的事情。我想在不子类化的情况下执行此操作,因为我在访问其他类的导出时遇到一些问题
编辑: 我的 socket 问题是我无法从我的子类更改它们的字符串值
if ([event keyCode]==126){
Myclass* c= [[Myclass alloc] init]; // the class that have the outlets
[c searchf];} //function that something interesting with the outlets
最佳答案
您可以使用一个委托(delegate)方法:
- (BOOL)control:(NSControl *)control textView:(NSTextView *)textView doCommandBySelector:(SEL)command {
if (control == yourSearchField && command == @selector(moveUp:)) {
// do custom stuff
return YES;
}
return NO;
}
关于objective-c - 管理 NSSearchfield 上的键盘事件,无需子类化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6178774/