2011-06-27 59 views

回答

1

要做到這一點,創建NSTextView的子類,並重寫-becomeFirstResponder像這樣:

- (BOOL)becomeFirstResponder 
{ 
    BOOL returnValue = [super becomeFirstResponder]; 
    if (returnValue) { 
     //do something here when this becomes first responder 
    } 

    return returnValue; 
} 

你可以在if語句設立NSNotification上方,使得當代碼塊得到運行,包含NSBox的視圖可以被調用並隨後在NSBox上繪製焦點環。爲了處理NSTextView失去焦點,你會想覆蓋-resignFirstResponder,就像這樣:

- (BOOL)resignFirstResponder 
{ 
    BOOL returnValue = [super resignFirstResponder]; 
    if(returnValue){ 
     //do something when resigns first responder 

    } 
    return returnValue; 
} 

一定要更改界面生成器類,並改變你的頭你的類類型和/或執行文件NSTextView的新子類:

enter image description here