在没有子类化的情况下管理NSSearchfield上的键盘事件(Manage keyboard events on a NSSearchfield without subclassing)

编程入门 行业动态 更新时间:2024-10-11 11:16:43
在没有子类化的情况下管理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 outlets

I 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; }

更多推荐

本文发布于:2023-08-08 00:17:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1466686.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:子类   情况下   键盘   事件   events

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!