2011-05-10 115 views
6

我的應用程序中有一個按鈕和一個NSTextView。我希望NSTextView在按下按鈕時獲得焦點。如果我通過鍵盤輸入文本,它應該在NSTextView中進行。專注於NSTextView

我應該在按鈕的操作方法中加入什麼代碼?

回答

9

假設你有一個名爲textView一個出口,這應該工作:

- (IBAction)buttonClicked:(id)sender { 
    NSButton *button = sender; 
    NSWindow *window = [button window]; 
    [window makeFirstResponder:textView]; 
}