skywinder / ActionSheetPicker-3.0

Quickly reproduce the dropdown UIPickerView / ActionSheet functionality on iOS.
http://skywinder.github.io/ActionSheetPicker-3.0
BSD 3-Clause "New" or "Revised" License
3.4k stars 740 forks source link

Ipad causing *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Failed to find Picker view's window. This may cause a memory leak.' #581

Closed Michael-Lumpp closed 4 days ago

Michael-Lumpp commented 1 month ago

Hi all, @skywinder @Wei18 This works perfectly fine for iPhone, even latest Swift5, however trying now on latest iPad, I get this error:

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Failed to find Picker view's window. This may cause a memory leak.'

It seems to be hitting this block:

- (void)addTapDismissAction {
    if (!self.pickerView) {
        NSAssert(_pickerView != NULL, @"Picker view failed to instantiate, perhaps you have invalid component data.");
        return;
    }
    if (self.windowTapActionRetryCount > 10) {
        NSAssert(NO, @"Failed to find Picker view's window. This may cause a memory leak.");
    }
    if (!self.pickerView.window) {
        self.windowTapActionRetryCount += 1;
        dispatch_async(dispatch_get_main_queue(), ^{
            [self addTapDismissAction];
        });
        return;
    }

I am calling the code like such:

 self.workplacePicker = ActionSheetStringPicker(title: "", rows:  workplaces, initialSelection: workplaceSelectedIndex,

                doneBlock: {
                    picker, index, value in
                   //my code here

                   self.Refresh()
                },
                cancel: { ActionSheetCancelBlock in

                   self.workplacePicker?.dismiss()

                },
                origin: lblJob)

              let btnCancel = UIBarButtonItem(title: Localized("Cancel"), style: UIBarButtonItem.Style.plain, target: self, action: nil)
              let btnEdit = UIBarButtonItem(title: Localized("Edit"), style: UIBarButtonItem.Style.plain, target: self, action: #selector(JobSettingsViewController.btnEditWorkplace(_:)))
              let btnAddNew = UIBarButtonItem(title: Localized("AddNew"), style: UIBarButtonItem.Style.plain, target: self, action: #selector(JobSettingsViewController.btnAddWorkplace(_:)))
              let btnSelect = UIBarButtonItem(title: Localized("Select"), style: UIBarButtonItem.Style.plain, target: self, action: nil)

            workplacePicker!.setCancelButton(btnCancel)
            workplacePicker!.setDoneButton(btnSelect)

              // Ensure the view is fully laid out
              self.view.setNeedsLayout()
              self.view.layoutIfNeeded()

              DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
                  guard let picker = self.workplacePicker else { return }
                  picker.show()

                  btnCancel.width = picker.toolbar.frame.width / 5
                  btnEdit.width = picker.toolbar.frame.width / 6
                  btnAddNew.width = picker.toolbar.frame.width / 6
                  btnSelect.width = picker.toolbar.frame.width / 6
                  picker.toolbar.items?.insert(btnEdit, at: 1)
                  picker.toolbar.items?.insert(btnAddNew, at: 2)
              }

Any ideas or support? thank you so much

Wei18 commented 1 month ago

@mlch911

mlch911 commented 1 month ago

@Michael-Lumpp I have tried your code. And it wouldn't trigger the assert you mentioned.

BTW, your code could not build. Did you write any extension code to ActionSheetStringPicker? We don't have the dismiss function.

Could you provide a demo project that can reproduce this assert? Maybe just use our demo app.

Wei18 commented 1 month ago

@mlch911

Please feel free to check related issue.

ddaddy commented 1 week ago

I'm also seeing this crash on iPad when presenting from a UITableViewCell

mlch911 commented 1 week ago

I'm also seeing this crash on iPad when presenting from a UITableViewCell

Could you provide a demo project?

ddaddy commented 1 week ago

Sure, here you go. Nothing fancy, just run it on the iPad simulator.

UIPicker Test.zip

Wei18 commented 4 days ago

Try 2.7.5