在没有子类化的情况下管理NSSearchfield上的键盘事件(Manage keyboard events on a NSSearchfield without subclassing)
我有一个有许多网点和NSSearchfield的视图,如果用户按下搜索字段中的向上箭头,我想对网点做一些有趣的事情。 我想这样做没有子类化,因为我从其他类访问出口有一些问题
编辑:我的问题是我不能从我的子类更改他们的字符串值
if ([event keyCode]==126){ Myclass* c= [[Myclass alloc] init]; // the class that have the outlets [c searchf];} //function that something interesting with the outletsI have a view with many outlets and a NSSearchfield, i want to do something interesting with the outlets if the user press up arrow in the searchfield. I want to do this without subclassing because i have some problems accesing the outlets from other class
EDIT: My problem with the outlets is that i can't change their stringvalue from my subclass
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; }There's a delegate method you can use:
- (BOOL)control:(NSControl *)control textView:(NSTextView *)textView doCommandBySelector:(SEL)command { if (control == yourSearchField && command == @selector(moveUp:)) { // do custom stuff return YES; } return NO; }更多推荐
发布评论