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?

DOLOisSOLO
  • 141
  • 1
  • 1
  • 12
  • 1
    What do you mean "switch between textfield methods"? What is it you want to do with this UITextField? – Seamus Campbell Aug 13 '13 at 17:03
  • You want your keyborad should not appear ? is that right? – Samkit Jain Aug 13 '13 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. – DOLOisSOLO Aug 13 '13 at 19:32

2 Answers2

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;
}
mattsven
  • 22,305
  • 11
  • 68
  • 104
  • This hides the keyboard, but setting the input view to a new view still displays the cursor in the textfield. – DOLOisSOLO Aug 13 '13 at 19:28
  • You can't get rid of the cursor, not without subclassing the UITextField. I've edited my answer with how to do that. – mattsven Aug 13 '13 at 23:14
0

Try this :

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

or

-(void)textFieldDidBeginEditing:(UITextField *)textField{
  [textField resignFirstResponder]; // hides keyboard
}
Samkit Jain
  • 2,523
  • 16
  • 33
  • 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. – DOLOisSOLO Aug 13 '13 at 19:34