zoukankan      html  css  js  c++  java
  • UITextView 点return 隐藏键盘

    iOS开发中,发现UITextView没有想UITextField中textFieldShouldReturn:这样的方法,那么要实现UITextView return键隐藏键盘,可以通过判断输入的字符是不是回车符来实现。

    首先,声明要实现UITextView 的delegate。


    @interface MyViewController :UIViewController <UITextViewDelegate> 


    然后, 设置textView的delegate.
    textView.delegate =self;

    通常在viewDidLoad中设置此属性,或在nib(或storyboard)中。

    最后,实现代理方法。


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

        if ([text isEqualToString:@" "]) { 
            [textView resignFirstResponder];  
           return NO; 
       } 
       return YES; 


    这样,就实现了iOS中UITextView return键隐藏键盘。

  • 相关阅读:
    树链剖分-bzoj1036
    POJ3489企鹅
    51nod 1130
    51nod-8-16
    51nod-8-15
    51nod 8-14
    51nod1582-n叉树
    51nod1574排列转换
    51nod1785数据流中的算法
    iOS开发--Swift 最近项目开发中遇到的一些小问题与解决方法
  • 原文地址:https://www.cnblogs.com/limicheng/p/3856347.html
Copyright © 2011-2022 走看看