Search code examples
objective-cxcode4nstextview

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?


Solution

  • 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)];