Pedro
Pedro

Reputation: 507

Hide Keyboard in objective c

I have several textfields in a view, and one to write the country.
I wish that when you press up in the testField country that was to another view where you have a UIPickerView to select the country.
Then place the following code associated with the event "Editing did begin" of _tfCountry.

- (IBAction)countryPressed:(id)sender {
    [_tfCountry endEditing:YES];

    [_tfAdress  resignFirstResponder];
    [_tfCountry  resignFirstResponder];
    [_tfName  resignFirstResponder];
    [_tfEmail  resignFirstResponder];
    [_tfTelephone  resignFirstResponder];
    [_tfTaxID  resignFirstResponder];

    [self save];
    _picker = [self.storyboard instantiateViewControllerWithIdentifier:@"PickerCountry"];
    _picker.delegate = self;

    [self.navigationController pushViewController:_picker animated:YES];
}

But the keyboard does not disappear as it should.
he remains on the screen and slap buttons of the next view.

he should not depararecer with "resignFirstResponder"?
what am I doing wrong?

i try to

[self.view endEditing:YES]

and did not work.

if I comment the part of change of view, the keyboard does not disappear but stops sending data to the textfield

Upvotes: 0

Views: 1605

Answers (1)

Nithin M Keloth
Nithin M Keloth

Reputation: 1595

Try to hide it with a delay.

    [self performselector:@selector(hideKB) withObject:nil afterDelay:0.1];


  -(hideKB){

   [_tfAdress  resignFirstResponder];
   [_tfCountry  resignFirstResponder];
   [_tfName  resignFirstResponder];
   [_tfEmail  resignFirstResponder];
   [_tfTelephone  resignFirstResponder];
   [_tfTaxID  resignFirstResponder];
    }

Upvotes: 3

Related Questions