开发者

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. Thank开发者_Python百科s


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.


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.


You should use the delegate methods of the UITextField

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

:)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜