BytesGuy
BytesGuy

Reputation: 4127

Disable hardware keyboard editing UITextField

I have a UITextField that, when tapped, brings up a UIPickerView (_myTextField.inputView = _myPicker;).

However, in the simulator I can use my Macs keyboard to type into the UITextField. This is not desirable as I am using the UIPickerView.

How can I disable, or ignore, the hardware keyboard input for the text fields that are using pickers?

Upvotes: 3

Views: 1048

Answers (2)

Stonz2
Stonz2

Reputation: 6396

You could use - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string to reject anything that has a single character input (e.g. a key press, which I believe would have a range.length of 1). This wouldn't help with copy/paste operations, but would cover single keystrokes.

Upvotes: 1

hcarrasko
hcarrasko

Reputation: 2352

is this that you are looking for?

-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
    // Here You can do additional code or task instead of writing with keyboard
    return NO;
}

I hope this help

Upvotes: 0

Related Questions