XtremeHek3r
XtremeHek3r

Reputation: 381

NSTextView always scrolls to bottom. How do I force it to display at the top?

I have an NSTextView in my XIB UI. In my code, I do

[textview insertText:@"text i put here"]; 

many times, and then finally

[textview setEditable:NO]; 

BTW, this is to create an information panel for my app.

When I run my app though, the text view always scrolls to the bottom. Is there any way to make it start at the top?

Upvotes: 0

Views: 1739

Answers (3)

Peter Ahlberg
Peter Ahlberg

Reputation: 1379

In Swift one can do

textView.scroll(NSPoint.zero)

where one loads content

Upvotes: 0

Chandu kumar.Alasyam
Chandu kumar.Alasyam

Reputation: 722

Try with this method

[textview scrollToBeginningOfDocument:self];

or

//NSTextView inside an NSScrollView you can create object for that scrollview

[scrollView.contentView scrollToPoint:NSMakePoint(0, scrollView.documentView.frame.size.height-scrollView.contentSize.height)];

Upvotes: 1

9dan
9dan

Reputation: 4282

If you insert a NSTextView with Interface Builder, it will actually reside inside of NSScrollView. Interface Builder automatically do this.

I mean, this is normal scroll view behavior and you can do 'scroll to top' as usually.

NSScrollView scrollToTop

Upvotes: 0

Related Questions