我正在尝试在新行中插入文本,而不删除文本视图中的上一个文本。我在iOS上很新,所以我很难解决这个问题。提前致谢
答案 0 :(得分: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;
}
答案 1 :(得分:0)
试试这个
将\ n添加到字符串时,它将转换为新的行符号
aTextView.text = [NSString stringWithFormat:@"%@\n%@",aTextView.text,@"Second Line"];
答案 2 :(得分:0)
textView.text = [(textView.text ?: @"") stringByAppendingString:(myText ?: @"")];