UITextField functionality with no keyboard

Solution:

In the end, I discovered another similar (but not exact) question here on stackoverflow, and one answer gave a solution to my problem. The way to go about it is simply to have the app display a dummy View as the keyboard, and everything else works the way it should.

UIView *dummyView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 1, 1)];    
VIN.inputView = dummyView; // Hide keyboard, but show blinking cursor

It works for UITextField and UITextView and they need to be set to editable.


The author's code...

UIView *dummyView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 1, 1)];    
VIN.inputView = dummyView; // Hide keyboard, but show blinking cursor

(Where 'VIN' is the UITextField variable, and this code is placed in somewhere like viewDidLoad)

...does work to prevent the iPhone/iPad popup keyboard to be displayed.

HOWEVER, that's just the 'display' portion of a keyboard interface. If you have an external keyboard attached such as Apple's physical iPhone/iPad keyboard that plugs into the 30-pin or one of a zillion Bluetooth enabled keyboards (or even using Mac keyboard with simulator), the user can still type into the field WITHOUT the display keyboard popup showing.

Also, even with no keyboard popup shown, the user would still be able to PASTE from the paste-board into the field by double-touching the field and selecting PASTE.

The following ADDITIONAL code prevents those keyboard from being used and prevents PASTE as well:

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    NSLog(@"myXViewController shouldChangeCharactersInRange");
    return FALSE;
}

...and still allows selection, but not editing of the text in the field.

Tags:

Uitextfield