• 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: Newbie Q : writing into a text view programmatically
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Newbie Q : writing into a text view programmatically


  • Subject: Re: Newbie Q : writing into a text view programmatically
  • From: Robert Walker <email@hidden>
  • Date: Fri, 7 Jul 2006 11:20:31 -0400

Oops sorry about that.  Thanks Henry!

I also found where that is stated about insertText:

insertText:
Inserts the given string into the receiver’s text storage.

- (void)insertText:(id)aString

Parameters
aString
Either an NSString or an NSAttributedString object.

Discussion
This method is the entry point for inserting text typed by the user and is generally not suitable for other purposes. Programmatic modification of the text is best done by operating on the text storage directly. Because this method pertains to the actions of the user, the text view must be editable for the insertion to work.



On Jul 7, 2006, at 11:11 AM, Henry McGilton wrote:


On Jul 7, 2006, at 7:01 AM, Scott Andrew wrote:

Delanoy,

you want to call.. [self setStringValue:s];

NSTextView does not implement any such method.



Scott Andrew

On Jul 7, 2006, at 12:48 AM, email@hidden wrote:


Hello all,

 is there a simple way to implement the following action
(say, a method in a subclass of NSTextView) :

    -(void)writeOut: (NSString*) s;

which makes the text view change (along with all
the data associated with it, such as the text conatiner
and the layout manager) exactly as if the user had
typed the string s on the keyboard ?

If the text you wish to set in the NSTextView is plain text, you use either of the – replaceCharactersInRange:withString: or – setString: methods of NSText (NSTextView's superclass). Always remember to look at a class's superclass . . .

If the text you wish to set in the NSTextView is rich text, you
must work with attributed strings, and then you use the
– replaceCharactersInRange:withAttributedString:  method of
the underlying NSTextStorage object (which is a subclass of
NSMutableAttributedString), which you get from the
NSTextView via the  -textStorage  method of NSTextView .

Somewhere in the documentation it states clearly that the
-insertText  method of NSTextView is for user-typed input, as
implemented by the  NSTextInput  protocol.  To set text
programmatically, you should use the methods as described here.

    Cheers,
        ........  Henry


===============================+============================ Henry McGilton, Boulevardier | Trilithon Software Objective-C/Java Composer | Seroia Research -------------------------------+---------------------------- mailto:email@hidden | http://www.trilithon.com | ===============================+============================


_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40mac.com


This email sent to email@hidden

-- Robert Walker email@hidden



_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Newbie Q : writing into a text view programmatically (From: email@hidden)
 >Re: Newbie Q : writing into a text view programmatically (From: Scott Andrew <email@hidden>)
 >Re: Newbie Q : writing into a text view programmatically (From: Henry McGilton <email@hidden>)

  • Prev by Date: Re: NSTableView - how to select text when editing a column?
  • Next by Date: where have all the IVARS gone? (long time passing...)
  • Previous by thread: Re: Newbie Q : writing into a text view programmatically
  • Next by thread: Re: Newbie Q : writing into a text view programmatically
  • Index(es):
    • Date
    • Thread