开发者

Manage keyboard events on a NSSearchfield without subclassing

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){
        M开发者_JAVA百科yclass* c= [[Myclass alloc] init]; // the class that have the outlets
        [c searchf];} //function that something interesting with the outlets 


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜