Auto scrolling to the end of NSTextView

て烟熏妆下的殇ゞ 提交于 2019-12-08 11:56:27

问题


I have a NSTextView on which I am appending console logs. I have implemented this UI in XIB file with scroll views. When my application appends the console logs in the text view, I want the scroll bar to automatically go to the end of the textview. I could not find any property in XIB editor. Any idea how can I achieve this?

@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];

回答1:


You can achieve your goal by using -[NSText scrollRangeToVisible:] after appending your string. (NSTextView is a subclass of NSText.)

Sorry, but that's the only way. As you observed, there's no IB check box that effects this particular behavior.

Apropos of nothing, you could replace your two -[NSMutableString appendString:] calls with one -[NSMutableString appendFormat:] call.



来源:https://stackoverflow.com/questions/16452110/auto-scrolling-to-the-end-of-nstextview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!