gpt4 book ai didi

ios - UITextView 在成为第一响应者时添加新行

转载 作者:技术小花猫 更新时间:2023-10-29 10:46:17 25 4
gpt4 key购买 nike

所以我有一个 UITextField,它是页面打开时的第一响应者(工作正常)。然后我有一个 UITextView 当用户按下返回时成为第一响应者,这就是我的问题所在。当按下返回时,第一响应者似乎工作正常,但 UITextView 添加一行并开始光标在第二行闪烁。有没有人可以帮助我?提前致谢!

这里是开关

- (BOOL)textFieldShouldReturn:(UITextField *)textField {
[textField resignFirstResponder];
[self.fieldDescription.textView becomeFirstResponder];

return YES;
}

看到图标在哪里闪烁了吗?这就是当第一响应者改变时它开始的地方...... enter image description here

最佳答案

很好的问题和描述。我遇到了完全相同的问题。

这个线程上没有答案为我解决了这个问题。有人在 another thread 的评论(@AndreiRadulescu)中放了一个链接。 . @rmaddy 在该线程上的回答解决了它。他的回答是:

One solution to solve this is when you implement the textFieldShouldReturn: delegate method, be sure to return NO, and not YES. By returning NO, the newline isn't passed on to the text field.

- (BOOL)textFieldShouldReturn:(UITextField *)textField {
// move to next field or whatever you need
[myTextView becomeFirstResponder];

return NO;
}

在 Swift 中:

//Dismisses keyboard upon tapping the return key
func textFieldShouldReturn(textField: UITextField) -> Bool {
txtTask.resignFirstResponder()
return false
}

关于ios - UITextView 在成为第一响应者时添加新行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21468717/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com