iOS菜鸟学习——UITextView return键隐藏键盘
来源:网络 责任编辑:栏目编辑 发表时间:2013-07-01 10:20 点击:次
iOS开发中,发现UITextView没有想UITextField中textFieldShouldReturn:这样的方法,那么要实现UITextView return键隐藏键盘,可以通过判断输入的字符是不是回车符来实现。
首先,声明要实现UITextView 的delegate。
[plain]
@interface MyViewController :UIViewController <UITextViewDelegate>
然后, 设置textView的delegate.
textView.delegate =self;
通常在viewDidLoad中设置此属性,或在nib(或storyboard)中。
最后,实现代理方法。
[plain]
-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString*)text
{
if ([text isEqualToString:@"\n"]) {
[textView resignFirstResponder];
return NO;
}
return YES;
}
这样,就实现了iOS中UITextView return键隐藏键盘。
摘自 soloterry的专栏
相关新闻>>
- 发表评论
-
- 最新评论 更多>>
今日头条
更多>>您可能感兴趣的文章
- ios学习笔记(二)xcode 4.3.2下实现基本交互
- iPhone开发学习笔记006—— NSNotification自定义通知名
- iphone开发之object c基础一定义接口
- (iPhone/iPad开发)presentViewController相应方法在SDK5.0前后
- Android:实现TabWidget选项卡按钮在屏幕下方
- iPhone应用开发之十一:常用的三种动画表现效果
- Memory on the iPhone
- ios开发问题:添加库和复制其它工程文件编译错误问题
- 多线程之NSInvocationOperation
- Lexical or Preprocessor Issue 'xxx.h