• 取消第一响应


    一,UITextView取消第一响应

        UITextView *editTextView = [[UITextView alloc] init];

        self.editTextView = editTextView;

        editTextView.returnKeyType = UIReturnKeyDone;

        [imageView addSubview:editTextView];

        editTextView.delegate = self;

    #pragma mark - UITextView Delegate Methods 

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

        if ([text isEqualToString:@" "]) {

        [textView resignFirstResponder];

            return NO;

        }

        return YES;

    }

    二,UITextField取消第一响应

    field.returnKeyType = UIReturnKeyDone;

    [field addTarget:self action:@selector(onKeyBoardDown:) forControlEvents:UIControlEventEditingDidEndOnExit];// 取消第一响应

    -(void)onKeyBoardDown:(id)sender{

        [sender resignFirstResponder];

    }

    或者

    - (void)textViewDidBeginEditing:(UITextView *)textView {
       UIBarButtonItem *done =    [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(leaveEditMode)] autorelease];
       self.navigationItem.rightBarButtonItem = done;    
    }

    - (void)textViewDidEndEditing:(UITextView *)textView {
        self.navigationItem.rightBarButtonItem = nil;
    }

    - (void)leaveEditMode {
        [self.textView resignFirstResponder];
    }

    或者

    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

    {

        [self.view endEditing:YES];

    }

  • 相关阅读:
    java程序高CPU,如何直接定位(linux系统下命令行操作)
    HashMap源码解读(jdk1.8)
    mysql索引原理
    redis常见问题
    Bitmap算法
    list遍历时删除的坑
    接口和抽象类有什么区别?各在什么场景下使用?
    记录BigInteger犯过的一个错误
    CentOS7切换源
    map遍历性能记录
  • 原文地址:https://www.cnblogs.com/pjl111/p/4196415.html
Copyright © 2020-2023  润新知