开发者

UITextfield in UITableViewCell resign FirstResnponder

开发者 https://www.devze.com 2023-03-11 12:12 出处:网络
I have a UITextfield of type NumberPad in a UITableViewCell. How can I m开发者_JAVA百科ake it resign first responder (i.e. dismiss the keyboard)?

I have a UITextfield of type NumberPad in a UITableViewCell. How can I m开发者_JAVA百科ake it resign first responder (i.e. dismiss the keyboard)? Thanks


You have to add a UIButton somewhere in your interface. I often do it on the navigation bar and then resign first responder when it is pressed.

There are all sorts of kludges to superimpose fake done buttons over the numberpad, but they are asking for trouble IMHO. It would be nice if Apple addressed this in future though as lots of people have the same issue.

Good discussion and other solutions here;

How to show "Done" button on iPhone number pad


Implement UITextFieldDelegate and set your UITextField delegate to it. In the -(BOOL)textFieldShouldReturn:(UITextField *)textField delegate method you set the resignFirstResponder call.

You can also set up an action to a button on the pad. You can do this by trying to add a done button to the pad. I know that in the most recent sdk this is somewhat impossible.

For those cases you have two options:

1.Add a done button somewhere on the view. If you are using a navigation controller you can add it to the navigation bar and simply set up the action for that button and in the action you resignFirstResponder for the UITextField.

2.Add your keyboard to a UIActionSheet and add the done button right on top of the keyboard.

0

精彩评论

暂无评论...
验证码 换一张
取 消