Hide Keyboard in objective c

心不动则不痛 提交于 2019-12-25 02:09:24

问题


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


回答1:


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];
    }


来源:https://stackoverflow.com/questions/22331963/hide-keyboard-in-objective-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!