• 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
NSTextView woes
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSTextView woes


  • Subject: NSTextView woes
  • From: Rick Bischoff <email@hidden>
  • Date: Mon, 21 Jun 2004 12:38:44 -0500

Hello,

I have an NSTextView that is uneditable, multiple fonts not allowed--
basically it just shows output from another command. I need to know
the "correct" way to append text into this view and have it use the
font I set previously.

As of now, I have the following code: (outputTV is NSTextView*)

[[outputTV textStorage] setFont:[NSFont userFixedPitchFontOfSize:9.0]];

in my class init function. In my appendText function:

-(void)appendText:(id)S {
NSRange theEnd = NSMakeRange([[outputTV string] length],0);
[outputTV replaceCharactersInRange:theEnd withString:S];
theEnd.location+=[(NSString*)S length]; // the end has moved
[outputTV scrollRangeToVisible:theEnd];
}

But next text is showing up with the default helvetica font and not the
fixedPitchFont I set in init. I realize that I can set the font every
time I append the text, but this seems wasteful and unnecessary.

In previous attempts at solving this problem, I tried the following:

-(void)appendText:(id)S {

NSMutableAttributedString* temp = [[outputTV textStorage]
mutableString];
[temp appendString:S withAttributes:attributes];

// etc
}

But that gave me an index out of bounds error somewhere-- I didn't
understand the error. I was under the impression that I could do this
because the documentation for "NSMutableAttributedString mutableString"
says that the receiver monitors changes to this string.


Rick Bischoff
Blog, and home for some MacOS X apps -- http://rickjr.org
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.


  • Follow-Ups:
    • Re: NSTextView woes
      • From: Satoshi Matsumoto <email@hidden>
    • Re: NSTextView woes
      • From: Douglas Davidson <email@hidden>
  • Prev by Date: Re: Sleeping and waking NSThread
  • Next by Date: Re: Where's the NSWindowController in a default document-based app
  • Previous by thread: Re: CFStream and Cocoa stream
  • Next by thread: Re: NSTextView woes
  • Index(es):
    • Date
    • Thread