2011-05-30 63 views
1

我有許多網點和NSSearchfield的視圖,如果用戶在搜索字段中按下箭頭,我想對網點做一些有趣的事情。我想這樣做,沒有子,因爲我有一些問題,與其他類accesing網點在沒有子類化的情況下管理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 
+0

我不認爲你可以做到這一點沒有繼承...什麼是更確切地說,你的問題與你的IBOutlet? – jlink 2011-05-30 16:45:19

回答

4

有你可以使用的代理方法:

- (BOOL)control:(NSControl *)control textView:(NSTextView *)textView doCommandBySelector:(SEL)command { 
    if (control == yourSearchField && command == @selector(moveUp:)) { 
     // do custom stuff 
     return YES; 
    } 

    return NO; 
} 
+0

我試過你的答案與NSLog,但我什麼也沒有得到。除了更改我的搜索字段的名稱外,我還得做其他事情。我從未使用委託方法 – 2011-05-30 16:59:19

+0

您是否設置了搜索字段的委託? – Wevah 2011-05-30 20:01:40

+0

我該怎麼做? – 2011-05-30 20:10:57

相關問題