Rocky
Rocky

Reputation: 1423

how to resign my keyboard when i stop typing

i am having 2 textfields, first one name is username and other is password and i want when i enter on password and click outside on view my keyboard should return how is this possible.Can anybody help me. Thanks

Upvotes: 1

Views: 982

Answers (3)

Inder Kumar Rathore
Inder Kumar Rathore

Reputation: 39978

You should use the delegate methods of the UITextField

- (void)textFieldDidEndEditing:(UITextField *)textField{
       [textField resignFirstResponder];
}

:)

Upvotes: 2

Parth Bhatt
Parth Bhatt

Reputation: 19469

You can use UITapGestureRecognizer and add it to your [self.view addGestureRecognizer:].

So in your tap gesture you can give the action which you want to perform.

Hope this helps you.

Upvotes: 2

Tim
Tim

Reputation: 60110

You'll need to define a method on your superview's delegate (usually your current view controller):

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    [super touchesEnded:touches withEvent:event];
    [self.myPasswordTextField resignFirstResponder];
}

This code tells your password text field (named myPasswordTextField in this example) to resign its first responder status. The first responder is the item handling input at present; when an object resigns first responder, it gives up its input-taking powers, which for a text field means hiding the keyboard and finishing editing.

Upvotes: 3

Related Questions