我正在尝试在新行中插入文本而不删除文本视图中的先前文本。我是 iOS 的新手,所以我很难解决这个问题。提前致谢
user3696707
问问题
151 次
3 回答
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;
}
于 2014-06-02T05:21:01.907 回答
0
尝试这个
当您在字符串中添加 \n 时,它将被转换为换行符
aTextView.text = [NSString stringWithFormat:@"%@\n%@",aTextView.text,@"Second Line"];
于 2014-06-02T05:09:45.990 回答
0
textView.text = [(textView.text ?: @"") stringByAppendingString:(myText ?: @"")];
于 2014-06-02T05:14:30.507 回答