PDA

View Full Version : Scrolling an NSTextView




Soulstorm
Jul 7, 2008, 08:40 AM
How can I scroll down programatically an NSTextView? My purpose is to make a text view scroll down as I add more things to the text view without any user interaction.

Any ideas?



robbieduncan
Jul 7, 2008, 08:54 AM
You can't. NSTextViews don't scroll. Scrollable NSTextViews as dragged in IB are actually 3 views: An NSScrollView contains an NSClipView contains an NSTextView.

Scroll the NSClipView via scrollToPoint: (http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Classes/NSClipView_Class/Reference/Reference.html#//apple_ref/occ/instm/NSClipView/scrollToPoint:) then update the scrollbars of the NSScrollView with reflectScrolledClipView: (http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Classes/NSScrollView_Class/Reference/Reference.html#//apple_ref/occ/instm/NSScrollView/reflectScrolledClipView:).

I'm sure you knew that already :)

Enuratique
Jul 7, 2008, 09:09 AM
The Googles, they do something (http://www.cocoabuilder.com/archive/message/cocoa/2002/10/14/55394).

CaptainZap
Jul 7, 2008, 09:38 AM
This might not be the most effective but I use it and it works
[textView scrollRangeToVisible: NSMakeRange ([[textView string] length], 0)];

Soulstorm
Jul 7, 2008, 03:54 PM
This might not be the most effective but I use it and it works
[textView scrollRangeToVisible: NSMakeRange ([[textView string] length], 0)];

Thanks. That worked out quite nicely.

You can't. NSTextViews don't scroll. Scrollable NSTextViews as dragged in IB are actually 3 views: An NSScrollView contains an NSClipView contains an NSTextView.

I tried that, but I just seemed not to be able to find that particular NSClipView.