开发者

How to dismiss the keyboard from the view?

I created the textfield programmatically for getting the value in it. Once i got the value in the textfield i wanted to dismiss the keyboard.

Could anyone help 开发者_高级运维me in this with sample code?

Thanks in advance.


If you are asking about iOS' keyboard, then you can do this:

[textField resignFirstResponder];

When a UITextField gains focus, it is said to have "gained first responder status", meaning that it is the first UIResponder in the responder chain. What this means to you is that when you send the resignFirstResponder message to a UIResponder, the receiver will be popped off the responder chain and the next responder in the chain will gain first responder status.


[inputView resignFirstResponder];


Create a text field delegate method that would send resignFirstResponder message to text field in question when "return" button is pressed:

// in some method
[myTextField setDelegate:self];

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

This code is off top of my head so doublecheck the delegate method title.


have one button Action

 UIButton *keyboard=[UIButton buttonWithType:UIButtonTypeCustom];
keyboard.frame = CGRectMake(0,100,320,460);
[keyboard addTarget:self action:@selector(keyDown) forControlEvents:UIControlEventTouchUpInside];

[self.view addSubview:keyboard];

in button action write this code

 -(void)keyDown{

[textfield resignFirstResponder];

}

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜