• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Programmatically inserting text into NSTextView and scrolling
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Programmatically inserting text into NSTextView and scrolling


  • Subject: Re: Programmatically inserting text into NSTextView and scrolling
  • From: Jason Coco <email@hidden>
  • Date: Sun, 21 Sep 2008 21:32:58 -0400


On Sep 21, 2008, at 21:05 , Rick Mann wrote:

I want to implement a simple console for my app. As it generates data, it outputs a string representation of it to an NSTextView in a window. Already this was fairly cumbersome to do, but I got it working. The part that doesn't work is that it doesn't automatically scroll the text up after new text starts getting appended beyond the bottom of the window.

How can I get it to do this?

You can do something like this:

// assume textView is a pointer to the actual text view
NSRange endRange = NSMakeRange([[textView string] length], 0);

// assume string already contains the data to add to this text view
[textView replaceCharactersInRange:endRange withString:string];
[textView scrollRangeToVisible:endRange];
[textView setNeedsDisplay:YES];

To complicate matters, how can I get it to do this only when the window was already scrolled to the bottom, and not when scrolled elsewhere (in the same fashion as Terminal.app)?

You would have to track whether or not the text view is at the end. I suggest looking at the documentation for NSTextView as well as the Scroll View Programming Guide:


http://developer.apple.com/documentation/Cocoa/Conceptual/NSScrollViewGuide/Articles/Introduction.html

HTH, Jason

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Programmatically inserting text into NSTextView and scrolling
      • From: Rick Mann <email@hidden>
References: 
 >Programmatically inserting text into NSTextView and scrolling (From: Rick Mann <email@hidden>)

  • Prev by Date: Re: Appropriateness of assign attribute and -fobj-gc-only
  • Next by Date: Re: NSScroller will be visible even it is below other view in 10.4
  • Previous by thread: Programmatically inserting text into NSTextView and scrolling
  • Next by thread: Re: Programmatically inserting text into NSTextView and scrolling
  • Index(es):
    • Date
    • Thread