我有一个 NSTextView,我正在其上附加控制台日志。我已经在带有 ScrollView 的 XIB 文件中实现了这个 UI。当我的应用程序在 TextView 中附加控制台日志时,我希望滚动条自动转到 TextView 的末尾。我在 XIB 编辑器中找不到任何属性。知道如何实现这一目标吗?
@property(nonatomic, strong) IBOutlet NSTextView *logTextView;
[[self.logTextView textStorage] beginEditing];
[[[self.logTextView textStorage] mutableString] appendString:iData];
[[[self.logTextView textStorage] mutableString] appendString:@"\n"];
[[self.logTextView textStorage] endEditing];
最佳答案
您可以在附加字符串后使用 -[NSText scrollRangeToVisible:]
来实现您的目标。 (NSTextView
是 NSText
的子类。)
抱歉,但这是唯一的方法。正如您所观察到的,没有 IB 复选框会影响此特定行为。
毫无疑问,您可以将两个 -[NSMutableStringappendString:]
调用替换为一个 -[NSMutableStringappendFormat:]
调用。
关于objective-c - 自动滚动到 NSTextView 的末尾,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16452110/