3

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?

BytesGuy
  • 3,932
  • 6
  • 33
  • 52
  • i dont think you need to do this, because you app is not going to run on mac system. so dont worry about it. but still you want to do this , you can set some valid characters for you text field. [reference link](http://stackoverflow.com/questions/14557925/ios-how-to-restrict-special-characters-in-uitextfield-except-dot-and-underscores) – Pawan Rai Mar 31 '14 at 19:17
  • 3
    @pawan But what if they have an external keyboard connected to an iPad for instance? They can use that in apps in the same way that the Mac keyboard can be used on the simulator. – David Mar 31 '14 at 19:30

2 Answers2

1

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.

Stonz2
  • 6,072
  • 4
  • 41
  • 60
0

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

HCarrasko
  • 2,033
  • 5
  • 29
  • 41
  • If I do that, the `UIPickerView` doesn't show when the `UITextField` is tapped, nothing happens. – BytesGuy Mar 31 '14 at 19:21
  • This would NOT work because @Newbzors specifically said they were using the picker as the `inputView` of the field. – Stonz2 Mar 31 '14 at 19:35