How Can I Know When NSTextView Loses Focus?
I wan开发者_如何学Ct to clear the selection of NSTextView
after it loses focus. How can I achieve that? Thanks in advance!
Kai.
Set up a delegate object (or use your app delegate) that conforms to NSTextDelegate
protocol. Then all you need to do is to implement textDidEndEditing:
to clear the selection. From the docs:
textDidEndEditing:
Informs the delegate that the text object has finished editing (that it has resigned first responder status).
- (void)textDidEndEditing:(NSNotification *)aNotification
Something like:
#ifndef NSZeroRange
#define NSZeroRange NSMakeRange(0,0)
#endif
- (void)textDidEndEditing:(NSNotification *)aNotification {
[myTextView setSelectedRange:NSZeroRange];
}
精彩评论