UITextField: can't type text but smilies, copy/paste, and backspace is fine
Asked Answered
P

2

6

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

the class implements: UITableViewDelegate, UITableViewDataSource and UITextFieldDelegate,

In the cellForRowAtIndexPath each cell.uiTxtField.delegate is set to self.

The following happens both in the simulator and on the real iPhone device:

  • When I set the pointer/finger in the UITextField the keyboard pops up and textFieldDidBeginEditing is triggered, that's fine and as expected.

  • When I leave the UITextField, textFieldDidEndEditing is triggered, that's also fine and as expected.

  • But when I start to type text, the cursor stops blinking but no text is typed to the UITextField.

  • I can copy and paste text by holding down the pointer/finger in a UITextField that contains text, select copy and then paste it in another UITextField (or the same).

  • The backspace works fine.

  • It also let's me type in symbols and smilies etc.

  • The only thing I can't type in is characters/letters and numbers

  • The return button doesn't trigger textFieldShouldReturn

Since textFieldDidBeginEditing and textFieldDidEndEditing is triggered I assume my delegate setup is fine, but I can't understand why I can't type text and why textFieldShouldReturn is not triggered.

This might be related.

Any help is appreciated.

Pietism answered 25/6, 2012 at 20:30 Comment(1)
i have the same problem..anyone knows the solution please help itHomocyclic
L
0

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

try putting a code like this in your implementation file...

@implementation CustomAlertClass <UITextFieldDelegate>

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
    //
    self.YourTextField.delegate = self;
}
return self;
}

@end
Lizarraga answered 4/9, 2013 at 12:51 Comment(0)
K
0

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

I had the same symptoms where I was definitely setting the delegate properly and textFieldDidBeginEditing and textFieldDidEndEditing were getting called, but textFieldShouldReturn and shouldChangeCharactersInRange were not getting called. I also could not type any characters, but I could copy paste into the text field. In my case I also happened to be putting the text fields inside cells in a UITableView. My situation was slightly different in that the delete button did not work.

Where I went wrong, was that I was not using a raw UITextField in my cells, I had my own subclass of UITextField. My subclass had a property 'isEditing', which I was modifying in the UITextFieldDelegate methods and used to figure out how to scroll the table view when the text field was selected. This was overriding the 'isEditing' method on UITextField with is used as the getter for the UITextField 'editing ' property. Once I got rid of my subclass isEditing property everything behaved as expected.

Kherson answered 4/12, 2013 at 2:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.