我有一个UITextView。当用户点击发送键时,我希望能够自动执行选择器。我怎样才能做到这一点?我知道UITextField有
- (BOOL)textFieldShouldReturn:(UITextField *)textField
答案 0 :(得分:9)
试试这个:
- (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;
}
希望有帮助!
答案 1 :(得分:1)
你可以使用
[self performSelector:@selector(aMethod) withObject:nil afterDelay:0.1];
in
- (BOOL)textViewShouldEndEditing:(UITextView *)textView
{
return YES;
}
希望它可以帮助你..