Understanding resignFirstResponder with UITextField

后端 未结 3 813
情深已故
情深已故 2021-02-06 11:23

I\'m trying to get rid of the keyboard when the user touch outside my UITextField, by using this method:

- (void) touchesBegan:(NSSet *)touches withEvent:(UIEven         


        
3条回答
  •  情深已故
    2021-02-06 11:45

    try

    [self.view endEditing:YES];
    

    Update:

    Take a boolean value and set it to false in init method. In your textFieldShouldReturn delegate method method, execute the code if it is false, skip otherwise

    - (BOOL) textFieldShouldReturn:(UITextField*)textField
    {
        if (!boolean)
        {
            // YOur code logic here
        }
        boolean = false;
    }
    

    in your method where you call the endEditing method, set boolean to true.

    boolean = YES;      
    [self.view endEditing:YES];
    

提交回复
热议问题