Thanks, Martin. I ended up doing this:

        NSAttributedString* as = [[NSAttributedString alloc] initWithString: s 
attributes: attrs];
        NSTextStorage* text = self.output.textStorage;
        [text beginEditing];
        [text appendAttributedString: as];
        [text endEditing];
        NSRange r = NSMakeRange(text.length, 0);
        [self.output scrollRangeToVisible: r];

The text wouldn't update until I called -scrollRangeToVisible. didChangeText 
might also have made it show up, but the scroll gives me the added benefit of 
scrolling to the new text.

Wish I had noticed that note you quoted. :-)

-- 
Rick

On Mar 16, 2010, at 22:25:27, Martin Hewitson wrote:

> Hi Rick,
> 
> I assume 'output' is your NSTextView. Right?
> 
> Firstly, you can append text more easily by doing:
> 
> 1)  [output insertText:mystring];
> 
> or
> 
> 2)  [[output textStorage] appendAttributedString:myAttributedString];
> 
> To get changes to show up, try
> 
> [output didChangeText];
> 
> You might not need that if you use 1) or 2), not sure. Normally that's for 
> subclasses of NSTextView, but the method you are using 
> (replaceCharactersInRange:withString:) is an NSText method, I believe. Just 
> to quote the documentation for that method:
> 
> "In most cases, programmatic modification of the text is best done by 
> operating on the text storage directly, using the general methods of 
> NSMutableAttributedString."
> 
> Best wishes,
> 
> Martin
> 
> On Mar 17, 2010, at 2:19 AM, Rick Mann wrote:
> 
>> Some time ago, I created a little console in my app, displaying characters 
>> received on a serial port. For the life of me, I can't find that app to see 
>> how I did it.
>> 
>> I'm currently using an NSTextView, and calling the following to append text:
>> 
>>   NSString* existingText = self.output.string;
>>   NSRange r = NSMakeRange(existingText.length, 0);
>>   [self.output replaceCharactersInRange: r withString: s];
>>   r = NSMakeRange(existingText.length, 0);
>>   [self.output scrollRangeToVisible: r];
>>   [self.output setNeedsDisplay: true];
>> 
>> The problem is that it doesn't always show up. I still have to mouse over 
>> the area before it'll display (sometimes).
>> 
>> Can anyone offer suggestions on how I can improve this behavior? Note: I 
>> like NSText view because I can style the text.
>> 
>> Thanks!
>> 
>> -- 
>> Rick
>> 
>> _______________________________________________
>> 
>> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
>> 
>> 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:
>> http://lists.apple.com/mailman/options/cocoa-dev/martin.hewitson%40aei.mpg.de
>> 
>> This email sent to martin.hewit...@aei.mpg.de
> 
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> Martin Hewitson
> Albert-Einstein-Institut
> Max-Planck-Institut fuer 
>    Gravitationsphysik und Universitaet Hannover
> Callinstr. 38, 30167 Hannover, Germany
> Tel: +49-511-762-17121, Fax: +49-511-762-5861
> E-Mail: martin.hewit...@aei.mpg.de
> WWW: http://www.aei.mpg.de/~hewitson
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 
> 
> 
> 
> 

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to