UITextField委托将捕获返回密钥:- (BOOL)textFieldShouldReturn:(UITextField *)textField
但它不会像UITextView那样做多行。但是UITextView,它能捕获返回键吗?
我需要捕获关键事件:(返回)并执行多行:"\n"....
我该怎么办? thx
答案 0 :(得分:9)
快速谷歌搜索“UITextView detect return”出现了这个帖子:
UITextView (editing) - detecting that next line event occured
(为方便起见,我发布了以下代码)
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text;
{
if ( [text isEqualToString:@"\n"] ) {
//Do whatever you want
}
return YES;
}