I am trying to Insert Text in new line without removing the previous text in Text View. I am very new in iOS so I am faciing little difficulty to solve this problem. Thanks in advance
Asked
Active
Viewed 157 times
1
-
1can you put your textView's code ? – iPatel Jun 02 '14 at 05:06
-
Are you asking how to append text? – CrimsonChris Jun 02 '14 at 05:08
-
possible duplicate of [UITextView insert text in the textview text](http://stackoverflow.com/questions/2792589/uitextview-insert-text-in-the-textview-text) – CrimsonChris Jun 02 '14 at 05:09
-
Please search for existing answers before posting a new question. – CrimsonChris Jun 02 '14 at 05:11
3 Answers
1
You can do it quite easily by using the following code :
NSString *oldText,*newText,*myString;
- (IBAction)addNewItem:(id)sender {
[self updateTextField];
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
return YES;
}
-(void)updateTextField
{
oldText=displayTextView.text;
newText=entryTextField.text;
myString = [newText stringByAppendingFormat:@"\n"];
myString = [myString stringByAppendingString:oldText];
displayTextView.text=myString;
}

Mahboob Nur
- 739
- 2
- 9
- 34
0
try this
When you add \n to the string, it will be converted to new line symbols
aTextView.text = [NSString stringWithFormat:@"%@\n%@",aTextView.text,@"Second Line"];

Vijay-Apple-Dev.blogspot.com
- 25,682
- 7
- 67
- 76
0
textView.text = [(textView.text ?: @"") stringByAppendingString:(myText ?: @"")];

CrimsonChris
- 4,651
- 2
- 19
- 30