XtremeHek3r
XtremeHek3r

Reputation: 381

How do I add text to a non-editable text view

I have a NSTextView in my XIB UI. I made the @property and everything, and I wrote the code

[self.output setEditable:NO];

I only want it to be user non-editable, but I want to be able to add text to it using

[self.output insertText:@"some text"];

Is there a non-user editable function or any way to do this? (I'm probably missing something.)

Upvotes: 0

Views: 122

Answers (2)

Daniel Le
Daniel Le

Reputation: 1830

You should grab and modify the NSTextView's textStorage: output.textStorage. It's an object of type NSTextStorage. Then you can modify it using the replaceCharactersInRange:withString: method of the superclass.

[self.output.textStorage replaceCharactersInRange:NSMakeRange(self.output.string.length, 0) withString:@" Hello, world!"];

A more straightforward approach is:

[self.output setString:[self.output.string stringByAppendingString:@" Hello, world!"]];

Upvotes: 1

Jef
Jef

Reputation: 4728

use this

[self.output setStringValue: @"some string" ];

setStringValue: is inherited from NSControl, along with setIntegerValue: setDoubleValue: etc, etc..

Upvotes: 0

Related Questions