如何滚动到NSTextView中的光标位置?

时间:2014-01-20 19:16:56

标签: macos scroll nstextview

如何以编程方式将NSTextView滚动到光标位置?

1 个答案:

答案 0 :(得分:1)

这应该有效

NSUInteger cursorPosition;
cursorPosition = [[[self.textView selectedRanges] firstObject] rangeValue].location;
[self.textView scrollRangeToVisible:NSMakeRange(cursorPosition, 0)];