1

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

Mahboob Nur
  • 739
  • 2
  • 9
  • 34

3 Answers3

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;


}

enter image description here

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"];
0

textView.text = [(textView.text ?: @"") stringByAppendingString:(myText ?: @"")];

CrimsonChris
  • 4,651
  • 2
  • 19
  • 30