I'm trying to set up a NSTextView like the console in Xcode (or pretty much any other IDE available). That being the user cannot edit the NSTextView, however they can put in a character when appropriate, I'm trying to set up that same functionality. No clue how to go about it. Any ideas?
Asked
Active
Viewed 311 times
1 Answers
0
You could simply make an action that appends a formatted string containing a line break, a time stamp, and your desired text to the text view. Here's an example:
- (void)addToLog:(NSString *)input
{
[[self.myTextView textStorage] appendAttributedString:[[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"\n%@: %@",[NSDate date],input]]];
}
So then instead of using NSLog(@"some text");
you could call [self addToLog:@"some text"];
and it would be added to a new line in your text view.

Mick MacCallum
- 129,200
- 40
- 280
- 281
-
This is what I've done with the log function, but I need to take input data. So I need to be able to only enter in characters in the NSTextView at a certain time, and reject all input at other times. Isn't there a delegate method to take a character in or something? – ManOx Nov 08 '12 at 22:00