gpt4 book ai didi

iphone - 当用户点击 iPhone 键盘上的“发送”按钮时,如何执行选择器?

转载 作者:行者123 更新时间:2023-12-03 20:21:04 27 4
gpt4 key购买 nike

我有一个 UITextView。当用户按下发送键时,我希望能够自动执行选择器。我怎样才能做到这一点?我知道 UITextField 有

- (BOOL)textFieldShouldReturn:(UITextField *)textField

最佳答案

试试这个:

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range 
replacementText:(NSString *)text; {
// Any new character added is passed in as the "text" parameter.
if ([text isEqualToString:@"\n"]) {
// If the Done button was pressed, resign the keyboard.
[textView resignFirstResponder];
// Return FALSE so that the final '\n' character doesn't get added.
return NO;
}
// For any other character return TRUE so that the text gets added to the view.
return YES;
}

希望有帮助!

关于iphone - 当用户点击 iPhone 键盘上的“发送”按钮时,如何执行选择器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7315542/

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