hackiftekhar / IQKeyboardManager

Codeless drop-in universal library allows to prevent issues of keyboard sliding up and cover UITextField/UITextView. Neither need to write any code nor any setup required and much more.
MIT License
16.46k stars 2.41k forks source link

UIAlertController with style UIAlertControllerStyleActionSheet #133

Closed swoot closed 9 years ago

swoot commented 9 years ago

If I'm editing a textField, then press a button that shows a modal view (i.e. UIAlertController) and close that, then as the keyboard shows I press the done button on the keyboard -> whole app goes down instead of just the view.

Steps to reproduce with the IQKeyboardManager example project:

  1. In SpecialCaseViewController.m, line 116, comment out the UIAlertView and insert
        UIAlertController* actionSheet = [UIAlertController alertControllerWithTitle:@"test" message:nil preferredStyle:UIAlertControllerStyleActionSheet];

        UIAlertAction* action = [UIAlertAction actionWithTitle:NSLocalizedString(@"cancel", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
        }];
        [actionSheet addAction:action];

        [self presentViewController:actionSheet animated:YES completion:nil];
  1. Run.
  2. Touch a textField
  3. Touch the Custom Work button
  4. Touch cancel on the UIAlertController
  5. Touch "done" in the keyboard
  6. boom.

So, am I doing something wrong in general with showing a modal view like that?

swoot commented 9 years ago

Note: if I call [self.view endEditing:YES]; before showing the modal view, the bug does not occur.

So might be just me and my faulty coding...

hackiftekhar commented 9 years ago

I will check and let you know my feedback on this.

hackiftekhar commented 9 years ago

It seems to be an iOS bug. Let me explain.

When we use UIAlertView/UIActionSheet then it present in it’s own UIWindow, so everything works fine as expected due to different UIWindow with proper UIKeyboard hide/show notifications. and it also doesn’t affect anything on our main UIWindow frame.

but when it is presented by UIAlertController then it is presented in our main UIWindow hierarchy. In this case UIKeyboard hide notifications are fired and then UIAlertController is presented. So works fine as expected. But when UIAlertController is dismissed then UIKeyboard show notifications are fired then UIAlertController is dismissed, and IQKeyboardManager find UIAlertController as UIWindow topController and fails to do the calculations.

Expected behaviour:- When UIAlertcontroller is presented then first UIKeyboard hide notifications should fire then UIAlertController should present, and when UIAlertController dismiss then first it should dismiss then UIKeyboard show notifications should fire.

Actual behaviour:- When UIAlertcontroller is presented then first UIKeyboard hide notifications is fired then UIAlertController is presented, but when UIAlertController dismiss then UIKeyboard show notification is fired then UIAlertController is dismissed.

I’ve improved the debugging functionality in current Library. Thanks for your bug report, This issue really need a standard solution.

hackiftekhar commented 9 years ago

This is fixed now. You can check the demo project also.

RuslanKim commented 8 years ago

ios 9/10.0.1 still a bug in IQK 4.0.5

hackiftekhar commented 8 years ago

@RuslanKim Can you share any demo?

RuslanKim commented 8 years ago

2016-09-20_16-01-22 we have no open source yet, but it seems we have a dialog: let alert = UIAlertController( title: title, message: message, preferredStyle: UIAlertControllerStyle.Alert) and if we call in editing mode a dialog 2016-09-20_16-02-08

hackiftekhar commented 8 years ago

If you cannot share a demo then I would suggest you to dismiss keyboard explicitly before presenting UIAlertController.

RuslanKim commented 8 years ago

It seems like it helps, but I hope it would be fixed .)

hackiftekhar commented 8 years ago

If you would like it to be fixed then you should share a demo and I can check if issue exist at library side or apple side.

Rotdev commented 6 years ago

@hackiftekhar We had the same issue and implemented the suggested workaround which fortuantely works. In principle we could also send you a version of the project with the bug, but I guess this is unpaid. I think it is described pretty accurately in the thread how you can replicate the bug, so from my point of view you/Apple could easily replicate the bug with about an hours worth of work. So I prefer that second solution, let me hear your thoughts. Thanks.

hackiftekhar commented 6 years ago

It would be better if you could share a demo project @Rotdev