tags:

views:

240

answers:

1

Newbie alert! I have a simple calculator with 4 text input fields. When I tap into a field the number pad appears and I enter numbers. No problems so far. Now, when testing this using the simulator I press return on the keyboard and using TextFieldShouldReturn my fields perform their calculations perfectly and the number keypad disappears nicely. The problem is, the number keypad does not have a 'Done' key so if I place a button let's say on the toolbar how do I code it to perform the action of the Return key?

+1  A: 

http://stackoverflow.com/questions/274319/how-do-you-dismiss-the-keyboard-when-editing-a-uitextfield

I asked the same question. :-)

the answer is that you set the delegate for the UITextField to your controller and impliment this method.

- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    [textField resignFirstResponder];
    return NO;
}

In response to your clarification

- (void)doneButtonPressed:(id)sender {
  [_textField resignFirstResponder];
  [self performCalculations];
}

You'll have to move all your calculations into the performCalculatinos method and make sure you have a variable that points to the UITextField.

kubi
I tried that already. Actually I saw your post. The problem is not with the keyboard disappearing. The keyboard disappears just fine cause I have placed a Done action in my .h file and then written the action in .m as:- (IBAction)done:(id)sender { [textfield1 resignFirstResponder]; [textfield2 resignFirstResponder]; [textfield3 resignFirstResponder]; [textfield4 resignFirstResponder]; }So this is called when I click/press the Done button on my toolbar but how do I now get the same behaviour as the Return key being pressed or the Done key being tapped on the normal iPhone keyboard?
Jovilla
I added to my answer, I hope that helped.
kubi