Reputation: 33048
I have customized UIAlertView a bit. My implementation inherits from UIAlertView and adds a textfield to it. If the textfield is tapped, the iPad's keyboard shows up. Would I would like to achieve in additon however:
The code of my custom alert view can be seen here: http://www.wildsau.net/post/2011/01/28/iOS-UIAlertView-with-a-UITextField-a-MonoTouch-implementation.aspx
Note that it is MonoTouch but any solution working for ObjC, I will be able to translate.
Upvotes: 3
Views: 3850
Reputation: 19323
To dismiss the keyboard when the user taps the alert's OK button, in the appropriate alert delegate method
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
do this:
[myTextField resignFirstResponder]
To dismiss your alert view programmatically, use this:
- (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated
Then you use the same code in clickedButtonAtIndex: to resignFirstResponder to cancel the keyboard.
Upvotes: 3