Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Michael-Lumpp opened this issue Sep 18, 2024 · 3 comments

Comments

@Michael-Lumpp
Copy link

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
Copy link
Collaborator

Wei18 commented Sep 19, 2024

@mlch911

@mlch911
Copy link

mlch911 commented Sep 23, 2024

@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
Copy link
Collaborator

Wei18 commented Oct 6, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants