I present UIAlertController action sheet from my UIViewController:
UIAlertController sheet = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleActionSheet];
[self presentViewController:sheet animated:YES completion:nil];
This works fine for the most part. Except when I have keyboard present, the sheet appears behind the keyboard. Is this expected behaviour? Is there another parameter I need to specify or present it from somewhere else?
It appears to be expected behaviour since the documentation says that alert controller with UIAlertControllerStyleActionSheet is presented within current context. Considering that the keyboard resides in another window, it does not share context with the presenting view controller.
For the purposes of my project, I decided to fall back on the old UIActionSheet, which presents over the keyboard no problem. However, if there are suggestions for UIAlertController, feel free to post as well.
Issue is not reproducible anymore. Probably it was fixed by or requires special hierarchy of view controllers. If we assume that this issue can still be reproduced in some circumstances I can suggest :
Hide keyboard when presenting UIAlertController
by calling UIView.endEditing(true)
where view is equal to UIViewConroller.view
or editable view (e.g. UITextView
)
Show keyboard after dismissing UIAlertController
if keyboard was presented before by calling UIView.becomeFirstResponder()
where view is view edited on first step
We can try do these steps in more general way, like creating an extension or subclassing UIAlertController
. But I believe we should not over complicate things
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With