Question

By default when tapping on a UITextField iOS will display a default keyboard. Is it possible to bypass this? I would like to display modally a custom view controller on tap on the textField and be able to edit the textField through this controller.

Is there a recommended way?

Was it helpful?

Solution 2

Ok tried out the exact requirement you asked for:-

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
    [textField resignFirstResponder];

    POCModalViewController *objPOCModalViewController = [[POCModalViewController alloc]init];
    [self presentViewController:objPOCModalViewController animated:YES completion:nil];

return NO;
}

Where POCModalViewController is the controller you want to present.

OTHER TIPS

Following wil repalce the keyboard as the input view when the user clicks on the UItextField.

self.TextField.inputView = "your view ";

I would like to post the solution i have finally implemented, which is the closest to Footyapps27 solution:

  1. I have made the controller that will present the modal controller(which will contain internally multiple custom keyboard views) as the uitextfield delegate for any UITextField objects contained within the view of my controller.

  2. I can now received any notification through the - (BOOL)textFieldShouldBeginEditing:(TWValueInput *)textField method when a textfield start to be edited:

Within that delegate method I have the following code snippet:

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {

            MyCustomKeyboardVC* vc = [[UIStoryboard storyboardWithName:@"main" bundle:nil] instantiateViewControllerWithIdentifier:@"customKeyboardController"];
            vc.delegate = self;


            self.modalPresentationStyle = UIModalPresentationCurrentContext;

            [self presentViewController:vc animated:NO completion:nil];

            return NO;
    }

returning NO within that method will prevent the default keyboard from being displayed. There is no need actually to call the resignFirstResponderon the textfield.

I should point out though that the Apple recommended way to display a custom keyboard is to provide a custom view to the textfield inputView property like Divya mentioned. Since i wanted to managed multiple keyboard view entries it was quicker for me to display a custom keyboard controller through the delegate method i mentioned above.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top