我有一个 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/