问题描述
|
我有一个带有许多网点和一个NSSearchfield的视图,如果用户按下搜索栏中的向上箭头,我想对网点做一些有趣的事情。我想这样做而不需要子类化,因为我在访问其他类的网点时遇到了一些问题
编辑:
我的网点问题是我无法从子类更改其stringvalue
if ([event keyCode]==126){
Myclass* c= [[Myclass alloc] init]; // the class that have the outlets
[c searchf];} //function that something interesting with the outlets
解决方法
您可以使用一种委托方法:
- (BOOL)control:(NSControl *)control textView:(NSTextView *)textView doCommandBySelector:(SEL)command {
if (control == yourSearchField && command == @selector(moveUp:)) {
// do custom stuff
return YES;
}
return NO;
}