开发者

How can I perform a selector when the user hits the Send button on the iPhone keyboard?

开发者 https://www.devze.com 2023-04-02 10:19 出处:网络
I have a UITextView. When the user hits the Send key I want to be able to automatically perform a selector. How can I do this? I know UITextField has

I have a UITextView. When the user hits the Send key I want to be able to automatically perform a selector. How can I do this? I know UITextField has

- (BOOL)textFieldShouldRetu开发者_如何学JAVArn:(UITextField *)textField


Try this out:

- (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;
}

Hope that Helps!


you can use

[self performSelector:@selector(aMethod) withObject:nil afterDelay:0.1];

in

- (BOOL)textViewShouldEndEditing:(UITextView *)textView 
{
  return YES;
}

Hope it helps you..

0

精彩评论

暂无评论...
验证码 换一张
取 消