UIAlertView with a text field: how to reject if the RETURN button is pressed, and how to hide the keyboard if it is rejected?

I tweaked the UIAlertView a bit. My implementation inherits from UIAlertView and adds a text box to it. If the text field is listened, the iPad keyboard appears. If I would like to add in addition:

  • If the user presses "OKAY" in warning mode, the keyboard does not disappear. How can I understand that?
  • The RETURN key is pressed on the keyboard, I would like to close the warning window (and, of course, hide the keyboard). Also here: how the hell ..?

My custom alert code can be seen here: http://www.wildsau.net/post/2011/01/28/iOS-UIAlertView-with-a-UITextField-a-MonoTouch-implementation.aspx

Please note that this is MonoTouch, but I can translate any solution that works for ObjC.

+3
source share
1 answer

To cancel the keyboard when the user clicks the Warning button in the corresponding notification delegation method

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex

do the following:

[myTextField resignFirstResponder]

To programmatically refuse to view alerts, use this:

- (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated

Then you use the same code in clickedButtonAtIndex: for resignFirstResponder to cancel the keyboard.

+3
source

Source: https://habr.com/ru/post/1793378/


All Articles