I have subclassed UIAlertView and inside which I am showing a textField which takes the input. When user clicks on textField the keyboard shows up and UIAlertView moves up to adjust for keyboard. But when I do [textField becomeFirstResponder] in didPresentAlertView delegate method of UIAlertView, the alertView doesn't moves up to adjust for keyboard. Instead the UIAlertView gets hidden behind the keyboard.
PS - I know that Apple says that UIAlertView should not be subclassed and to be used as it is, but I am subclassing UIAlertView because I want to redesign the Apple's default UI elements in it.
You should really not do something against Apple's recommendation.
Reasons
UIViewsubclass.As an alternative, Apple has made provision in the
UIAlertViewfor this requirement. You don't need to add a textfield to the alert view, instead, use theUIAlertViewpropertyalertViewStyle. It accepts values defined in the enumUIAlertViewStyleExample, lets assume a use case that you want to accept password from the user. The code to achieve this is as below.
To validate the input, lets say password entered must be minimum 6 characters, implement this delegate method,
To get the user input
To re-iterate,
UIAlertViewhas a private view hierarchy and it is recommended to use it as-is without modification. If you use it against recommendation you will get unexpected results.From Apple docs
This is standard technique used even in iOS default apps (Ex: Entering Wi-Fi password, etc.), hence using this will ensure you don't face issues like the one you mention.
Hope that helps!