Reputation: 1
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.
Upvotes: 0
Views: 505
Reputation: 1061
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];
}
Upvotes: 0
Reputation: 49354
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.
Upvotes: 1
Reputation: 163308
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.
Upvotes: 3