6

I am currently developing a prototype that I want to do user testing on desktop first before loading to iPad.

I am looking for solutions to disable the keyboard after clicking a textfield. That means after clicking a textfield, user is able to enter information from the macbook keyboard directly, and the virtual keyboard that automatically shows up in the simulator will not appear. I have been through a lot of tutorials but they are all dismissing the keyboard after user entry; that is not what I am looking for. How should I hide the keyboard?

Thanks so much!

hgwhittle
  • 9,316
  • 6
  • 48
  • 60
user3185617
  • 65
  • 1
  • 5

3 Answers3

9

Use this:

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

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

What you did Here:
You created a dummy view of width=hight=0, & assigned it as the inputView of your textField.

How It works: Instead of showing default, keyboard, now, the viewController is showing DummyView as inputView for your UITextField. As DummyView has Width=height=0, You will not see anything on the screen :)

Prince Agrawal
  • 3,619
  • 3
  • 26
  • 41
2

Here is another answer which I found the same hack but with little additional supportive code snippet to hide the blinking cursor too.

-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
    return NO;  // Hides both keyboard and blinking cursor.
}

I needed this to be done for a Quantity text field where I increase/decrease the quantity using a UIStepper view. So I needed the keyboard to be hidden always.

Community
  • 1
  • 1
Randika Vishman
  • 7,983
  • 3
  • 57
  • 80
1

This will set the inputView of your textField to, basically, an empty UIView with no frame.

self.theTextField.inputView = [[UIView alloc] initWithFrame:CGRectZero];
hgwhittle
  • 9,316
  • 6
  • 48
  • 60