Question

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];
Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top