As suggested earlier, setSelectedRange: will do the BUT trick!
If your goal is to completely remove the selection and cursor, fe if you subclass NSTextView to support similar behavior like NSTextEdit , in case of changing the status of firstResponder you should write:
- (BOOL)resignFirstResponder { // Invalid range location will remove cursor too [self setSelectedRange:NSMakeRange(NSUIntegerMax, 0)]; return YES; } //------------------------------------------------------------------------------ - (BOOL)becomeFirstResponder { [self setSelectedRange:NSMakeRange(0, self.string.length)]; return YES; } //------------------------------------------------------------------------------
source share