开发者

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜