She*_*lam 2 iphone cocoa-touch objective-c uitextview
我有一个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;
}
Run Code Online (Sandbox Code Playgroud)
希望有帮助!