This is a follow-up question of a more general nature related to : 

Re: How do you set the text in an NSTextView?

On May 7, 2010, at 11:49 AM, Douglas Davidson wrote:

> On May 7, 2010, at 9:41 AM, Bill Hernandez wrote:
> 
>>      [textView insertText:myString];
> 
> You don't want to call insertText: for this.  From the documentation:  "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."
> 
> The simplest way to set the entire contents is to call setString:.  More 
> detailed modifications are best done by operating on the text storage, which 
> is a subclass of NSMutableAttributedString.
> 
> Douglas Davidson

Douglas,

As a general learning excercise :

I was looking at NSTextView this morning to make sure I understood where I had 
gone wrong and make corrections in my logic, but am a little confused right now 
and would be grateful for any insights.

When I was learning how to access the docs after watching some of the 
introductory videos, I noticed that rather than scan the Class, or Instance 
Methods for something that might do what you need, as I recall a recommended 
procedure was to hold down the option key and double click on the class name 
(in this case NSTextView) and once the help window became available, up the 
Tasks section.

Once in the Tasks section look for a topic that might fit what you are trying 
to accomplish. Then if you can't find a solution, the next step would be to 
look at each superclass, all the way back NSObject to see if there is something 
that might work for your needs. 

So I went back to trace those steps to see where I went wrong and I noticed 
that if I open Tasks the only thing I see that looks like it might do what I 
need is "InsertingText" and when I click on that, the least scary method from a 
novice's point of view appears to be "– insertText:". I remembered that as I 
had looked through the Instance Methods earlier I couldn't find anything that 
would give me a clue to use setString.

The funny part was that I remembered {"- string:", "- setString:"} from before, 
but when I saw "– insertText:" and hovered the cursor over it : 
----------------------------------
insertText:
----------------------------------
Inserts aString into the receiver’s text at the insertion point if there is 
one, otherwise replacing the selection.
----------------------------------

and if I would have read a little further, I would have seen : 
----------------------------------
- (void)insertText:(id)aString
----------------------------------
Parameters
aString
The string to insert. aString can be either an NSString object or an 
NSAttributedString object.
Discussion
The inserted text is assigned the current typing attributes.

This method is the means by which text typed by the user enters an NSTextView. 
See the NSInputManager class and NSTextInput protocol specifications for more 
information.

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.
----------------------------------

After you mentioned that I should have used {"- string:", "- setString:"} and I 
went to the superclass NSText docs, I searched for "– string", and found that 
the topic for "– string" is : 

----------------------------------
Getting the Characters
----------------------------------
– string

My normal instinct would have never led me to look at "Getting the Characters" 
because that leads me to think "INDIVIDUAL Characters", not something like 
{"Getting the String Value", "Setting the String Value", etc}.

Grant it, I should have remembered from when I was learning about NSTextView 
objects, but the real question for me, is how would you proceed trying to get 
quick help on a specific Task that you might need to accomplish, without 
spending an hours researching each command that you intend to use ?

If I was interested in finding a method to help me solve a problem how would I 
best proceed (pretending we had never heard of NSTextView and this was our 
first encounter with it).

The reason I ask insights on how to proceed, is that Cocoa is so massive that 
you could spend years reading before you actually wrote any code.

Thanks for any help...

Bill Hernandez
Plano, Texas












_______________________________________________

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