UITextField / UITextView:我需要能够检测到用户"返回"关键,我需要能够做多线...什么可以做到?

时间:2012-05-02 23:31:33

标签: objective-c cocoa-touch

  

可能重复:
  How to create a multiline UITextfield?

UITextField委托将捕获返回密钥:- (BOOL)textFieldShouldReturn:(UITextField *)textField

但它不会像UITextView那样做多行。但是UITextView,它能捕获返回键吗?

我需要捕获关键事件:(返回)并执行多行:"\n"....我该怎么办? thx

1 个答案:

答案 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;
}