3

I'm wondering how to disable the inputview of a UITextfield. Setting textField.inputView = nil; or [textField setInputView:nil] in ShouldBeginEditing doesn't do anything, and using the userInteraction property removes the ability to interact with the field. Ideally, I'd like to remove both the cursor and the keyboard while still being able interact with and switch between textfield methods, using ShouldBeginEditing and ShouldEndEditing. Is there any way to accomplish this?

3
  • 1
    What do you mean "switch between textfield methods"? What is it you want to do with this UITextField? Commented Aug 13, 2013 at 17:03
  • You want your keyborad should not appear ? is that right? Commented Aug 13, 2013 at 17:18
  • I've got a couple of UITextfields. Currently I'm using the textFieldShouldBeginEditing and textFieldShouldEndEditing to determine which field is currently active for setting things like a textfield highlight or left/right view images. Commented Aug 13, 2013 at 19:32

2 Answers 2

2

You should do this:

myTextField.inputView = UIView.new; //Empty UIView

Setting it to nil just means the default keyboard is used.

To get rid of the caret, subclass the UITextField and override caretRectForPosition:

- (CGRect) caretRectForPosition:(UITextPosition*)position
{
    return CGRectZero;
}
Sign up to request clarification or add additional context in comments.

2 Comments

This hides the keyboard, but setting the input view to a new view still displays the cursor in the textfield.
You can't get rid of the cursor, not without subclassing the UITextField. I've edited my answer with how to do that.
0

Try this :

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

or

-(void)textFieldDidBeginEditing:(UITextField *)textField{
  [textField resignFirstResponder]; // hides keyboard
}

1 Comment

Neither solution really work in this case. I still need the textfield to be active in order to determine what properties to set for each textfield I have in my view.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.