> 
> 
> On Sep 22, 2010, at 4:03 AM, albert jordan wrote:
> 
>> 
>> I have setup an "NSTextView in an NSScrollView" item in interface builder, 
>> and my window controller objects has an IBOutlet that is linked to TextView 
>> of the item (if I connect it to the NSScrollView, I don't get any text).  
>> Anytime that I get a log statement, I use the insert text method to print 
>> out the log line in the view...
>> 
>> [myTextView insertText: (NSString *) newLogLine];
>> 
>> 
I found the following configuration useful when logging to an NSTextView 
instance

        [[_textView layoutManager] setBackgroundLayoutEnabled:YES];
        [[_textView layoutManager] setAllowsNonContiguousLayout:YES];

I also add the following in an NSTextView subclass to append a string and 
scroll it visible.

- (void)addStringAndScrollToVisible:(NSString *)string
{
        NSRange endRange;

        @try{
                
                endRange.location = [[self textStorage] length];
                endRange.length = 0;

                [self replaceCharactersInRange:endRange withString:string];
                endRange.length = [string length];
                
                // note that this method can be very slow for large amounts of 
text.
                //depending on how the textview is configured
                [self scrollRangeToVisible:endRange];
                
        } @catch (NSException *e){
                NSLog(@"Exception scrolling NSTextView: %@", [e name]);
        }
}

Regards

Jonathan Mitchell

Developer
Mugginsoft LLP
http://www.mugginsoft.com_______________________________________________

Cocoa-dev mailing list ([email protected])

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 [email protected]

Reply via email to