Popular Posts

There was an error in this gadget

May 15, 2011

Show/Hide keyboard For iPhone




When user writes something in the textfield a keyboard appears.But when the user finish his typing to the textfield, how to hide the keyboard?
Here is some code... that makes the keyboard hidden...



- (BOOL)textFieldShouldReturn:(UITextField *)theTextField {
    // When the user presses return, take focus away from the text field so that the keyboard is dismissed.
    if (theTextField == textField) {
        [textField resignFirstResponder];
        // Invoke the method that changes the greeting.
        [self updateString];
    }
    return YES;
}


- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    // Dismiss the keyboard when the view outside the text field is touched.
    [textField resignFirstResponder];
    // Revert the text field to the previous value.
    textField.text = self.string;
    [super touchesBegan:touches withEvent:event];
}

No comments:

Post a Comment