xmartlabs / XLForm

XLForm is the most flexible and powerful iOS library to create dynamic table-view forms. Fully compatible with Swift & Obj-C.
MIT License
5.77k stars 953 forks source link

XLFormDatePickerCell created multiple times after UIAlertView closes (firstResponder is called) - issue only since iOS 8.3 #423

Closed roland9 closed 9 years ago

roland9 commented 9 years ago

Issue Description

If you use an inline date cell (XLFormRowDescriptorTypeDateInline) in your form, there is an issue if you have UIAlertViews: after the Alert View closes, the form adds a second XLFormDatePickerCell as shown in the screenshot.

Note: This issue is only happening on SDK >= iOS 8.3. It's not reproducible on < iOS 8.3. So I assume in iOS 8.3 the handling of the firstResponder after the alert view closes has been changed. Note 2: This issue also happens if you use the iOS 8 only UIAlertController instead of the UIAlertView.

How to reproduce:

  1. To bring up an Alert View, add the following lines in viewDidLoad of the DatesFormViewController in the XLForm example project:
  dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^(void){
    [[[UIAlertView alloc] initWithTitle:@"testing" message:@"just hit cancel" delegate:nil cancelButtonTitle:nil otherButtonTitles:@"Cancel", nil] show];
  });
  1. Launch the XLForm example app, tap 'Date & Time'
  2. On the 'Date & Time' screen, open the inline date picker e.g. by tapping on the third cell called 'Date Time'.
  3. After 3 seconds, the UIAlertView shows up. Tap Cancel.
  4. You have two XLFormDatePickerCell cells now.

    Details:

Here is the call stack - seems UIKit is calling becomeFirstResponder, and that causes the new XLFormDatePickerCell to be created:

2

roland9 commented 9 years ago

There is a simple workaround for this issue: call endEditing before opening the AlertView:

    [self.view endEditing:YES];

That closes the XLFormDatePickerCell and thus no duplicates are created

pastorin commented 9 years ago

@roland9,

You have to use UIAlertController in iOS 8 since UIAlertView is deprecated. We test the issue using that and it works fine.

I just make a pull request replacing all UIAlertView and UIActionSheet for UIAlertController. Thanks for reporting

Regards, Martin