0

In my iOS application, on "More Information Screen" I have 10-12 UITextField to get user information.

User needs to type all information except "State".

When user clicks on "State" UITextField >> New UITableViewController is pushed.

Everything works fine, but when user clicks on "State" field "Keyboard" should get dismissed which is opened due to other fields like "City", "Address".

enter city. state view

For this I have added "Tag = 1" to "State" UITextfield, When user clicks on "State" field keyboard should get dismissed and new view should get loaded.

I have added following code but no luck:

- (void)textFieldDidBeginEditing:(UITextField *)textField{

    if(textField.tag == 1){
        [txtCity resignFirstResponder];
        [textField resignFirstResponder];
        [self.view endEditing:YES];
        //load state listing
        SelectStateProvince *selectStateProvince = [[SelectStateProvince alloc] initWithStyle:UITableViewStyleGrouped];
        selectStateProvince.parentViewName = @"Respondent";
        [self.navigationController pushViewController:selectStateProvince animated:YES];
    }
}

Am I missing something? Please suggest.

Thank you.

Abhishek Jain
  • 4,557
  • 2
  • 32
  • 31
User_1191
  • 981
  • 2
  • 8
  • 24

1 Answers1

1

I would suggest to use the below implementation.. Move the code to show the picker to should begin delegate..

   func textFieldShouldBeginEditing(_ textField: UITextField) -> Bool {

        if(textField.tag == 1){
            //load state listing
            SelectStateProvince *selectStateProvince = [[SelectStateProvince alloc] initWithStyle:UITableViewStyleGrouped];
            selectStateProvince.parentViewName = @"Respondent";
            [self.navigationController pushViewController:selectStateProvince animated:YES];
            return false
        } else {
           return true
        }
    }
Akhil
  • 170
  • 1
  • 13