【问题标题】:textFieldShouldReturn method of UITextviewUITextview 的 textFieldShouldReturn 方法
【发布时间】:2014-08-24 15:44:45
【问题描述】:

需要向用户显示一个多行文本字段以供评论输入,我使用的是 UITextView 而不是 UITextField。我想在我的 UITextView 上使用textFieldShouldReturn 将数据发送到服务器。我该怎么做?根据我目前的阅读,该方法仅适用于 UITextField。那么 UITextView 的等价物是什么?

【问题讨论】:

标签: ios keyboard xcode5 uitextview


【解决方案1】:

通过将 UITextViewDelegate 添加到您的 viewControllerHeader

@interface ViewController : UIViewController<UITextViewDelegate>

这将允许您访问 UITextViewDelegate 方法,其中有几个方法可以让您知道用户何时按下回车键或让您知道他们何时完成编辑,例如

 - (void)textViewDidEndEditing:(UITextView *)textView{

//From here you can action your methods to send the data to your server as required etc.

}

还有这个方法

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{

//Which you can use to listen for the @"\" return action if you prefer.

}

希望对你有帮助

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-10
    • 1970-01-01
    • 1970-01-01
    • 2011-01-19
    • 1970-01-01
    相关资源
    最近更新 更多