I have an NSTextView that I need to insert a line break in. The code looks like this:
NSString *myString = @"test" [myTextView insertText:myString]; /**** INSERT LINE BREAK HERE ****/ [[myTextView textStorage] insertAttributedString:MY_ATTRIBUTED_STRING atIndex:myString.length];
Anybody have any idea how to do this?
I believe you can use the literal \n for a newline
NSString *myString = @"test\n"
[myTextView insertText:myString];
I'm way late to the game here, but there's something that needs mentioning:
NSTextView is a subclass of NSResponder. NSResponder declares but does not implement a method
-insertNewline:
NSTextView does implement that method. That's the way to do it, not manually building a string with '\n'.
I agree with Jason. Use \n. I KNOW it works for iPhone, so it should definitely work for Mac.
Also, you forgot a semicolon on the end of the first line ;)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With