I have create UITextField with alert view. After typing on UITextField I want to hide keyboard when user click “done” button.
This is my code. When I run it it’s hitting the hideKeyBoard method (I found out using NSLog and the debugging). But this code not hiding the keyboard. Please Help me.
- (IBAction)doAlertInput:(id)sender
{
UIAlertView *alertDialog;
alertDialog = [[UIAlertView alloc]
initWithTitle: @"Please Enter Your Email Address!" message:@"You won’t see me"
delegate: self cancelButtonTitle: @"Ok" otherButtonTitles: nil];
userInput=[[UITextField alloc] initWithFrame: CGRectMake(12.0, 70.0, 260.0, 25.0)];
userInput.returnKeyType = UIReturnKeyDone;
[userInput addTarget:self action:@selector(hideKeyBoard) forControlEvents:UIControlEventEditingDidEndOnExit];
[userInput setBackgroundColor:[UIColor whiteColor]];
[alertDialog addSubview:userInput];
[alertDialog show];
[alertDialog release];
}
-(void)hideKeyBoard
{
[userInput resignFirstResponder];
NSLog(@"Key Board Hid");
}
After appering the key board its covering the alert view. So what i am doing is shift up my alert view little higher. Then it will be not a problem because key board doesn’t cover the alert view any more.
The first parameter of CGAffineTransformMakeTranslation() is the X coordinate to move the origin of the view to. The second parameter is the Y location to move the origin of the view to. 130.0 doesn’t exactly center the alert view between the status bar and the keyboard.
You’ll need to add these two lines somewhere between the UIAlertView instantiation and the [UIAlertView show] line. I put them directly before the show line.
Also add the CoreGraphics framework to your project.
I think this will help you. Thank you 🙂