views:

685

answers:

2

I would like to add new lines of text to my UITextView for my iPhone app. Basically my textview starts with a single line, and as app advances, new lines are added. However I can add only to the end or beginning of the existing text. How can I make such an entry into a new line. Can I manually send \n to the textview.text at a calculated range/location.

E.g. of what I mean. line 1: This is first line of text. This is second line 2: line of text. ---

I want: line 1: This is first line of text. line 2: This is second line of text.

Thanks!

A: 

You can use -[NSString stringByReplacingCharactersInRange:withString:] to modify the text of the UITextView. You can then assign that string as the new text object of the UITextView.

NSString *text = @"line 1. test line 2";

// Delete 'test' from the string
NSString *replacement = [text stringByReplacingCharactersInRange:NSMakeRange(8, 5) withString:@""];
JoostK
A: 

I have just beginning learn about iphone sdk and I don't know how to add a UITextView. My mean to be create a new object UITextView to appear a string. that on.

THPhuoc