UITextField: cannot enter text, but emoticons, copy / paste and backspace are ok

I think this is strange, I created my own class that inherits from UIAlertView. In this class, I add a UITableView as a subview, and the cells contain UILabel and UITextField.

the class implements: UITableViewDelegate, UITableViewDataSource and UITextFieldDelegate,

In cellForRowAtIndexPath, each cell.uiTxtField.delegate element is set to self.

In the simulator and the real iPhone device, the following happens:

  • When I set the pointer / finger in a UITextField, the keyboard pops up and textFieldDidBeginEditing starts, which is fine and as expected.

  • When I leave UITextField, textFieldDidEndEditing is triggered, it is also fine and as expected.

  • But when I start typing, the cursor stops blinking, but the text is typed on a UITextField.

  • I can copy and paste the text while holding the pointer / finger in a UITextField that contains the text, select the copy and then paste it into another UITextField (or the same one). p>

  • backspace works great.

  • It also allows me to enter characters and emoticons , etc.

  • The only thing I can not enter is the characters / letters and numbers

  • The return button does not execute a textFieldShouldReturn trigger

Since textFieldDidBeginEditing and textFieldDidEndEditing are running, I assume my delegate setting is fine, but I can’t understand why I cannot print text and why textFieldShouldReturn does not start.

It may be related.

Any help is appreciated.

+6
source share
2 answers

Do you put this in the "init" method of your custom class?

try putting such code in your implementation file ...

@implementation CustomAlertClass <UITextFieldDelegate> - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { // self.YourTextField.delegate = self; } return self; } @end 
0
source

Short answer: Make sure you don’t have any code that spoils the 'editing' property on UITextField.

I had the same symptoms when I definitely set the delegate correctly, and textFieldDidBeginEditing and textFieldDidEndEditing were called, but textFieldShouldReturn and shouldChangeCharactersInRange were not called. I also could not enter any characters, but I could copy the paste into the text box. In my case, I also accidentally placed text fields inside cells in a UITableView. My situation was slightly different from the fact that the delete button does not work.

Where I did wrong was that I did not use the raw UITextField in my cells, I had my own subclass of UITextField. My subclass had the isEditing property, which I changed in the UITextFieldDelegate methods and used to figure out how to scroll through the table view when selecting a text field. This was an override of the isEditing method on a UITextField, which is used as a getter for the editing property of UITextField. As soon as I got rid of my isEditing subclass, everything went as expected.

0
source

Source: https://habr.com/ru/post/918991/


All Articles