If you edit the UITextField.text property directly the UITextFieldDelegate will not fire. Is there a proper way of using the UITextField with a custom input view? I created my own numberpad viewcontroller, and I can modify the UITextField.text but I can not get the cursor location if I don't receive events from UITextFieldDelegate.shou开发者_JAVA百科ldChangeCharactersInRange.
Any idea on what's the proper way of using a custom input with UITextField?
please make sure
yourTextField.delegate = self
this line in your implementation file
I also created a custom numpad for our application. You're right that shouldChangeCharactersInRange
doesn't respond to programmatic text changes (via setText). We use the UIControlEventEditingChanged
event on the text field:
[aField addTarget:self action:@selector(editingChanged:) forControlEvents:UIControlEventEditingChanged];
Unfortunately, there's currently no way to access the cursor position of a UITextField outside of shouldChangeCharactersInRange. You can insert text at the cursor using this pasting method. As for a custom delete key, we are going with the "always delete the last character in the field" rule for now.
精彩评论