UIPickerView button not worked

Actually it is not my case. Few of my customer experienced.

Picker view has 2 buttons "Done" and "Cancel".
When user press Done or Cancel, a gray rounded rect popup view(with text "Done" or "Cancel" which user pressed) appeared and disappeared soon like toast message.
In "Cancel" button has only dismiss dialog only.

I cannot reproduce that in my iPhone. Only few users experienced this.

How can I fix this issue?
Is it depends on settings or something?

How can I add image or link to this post?
You cannot add any image in the forum, so bad !

Picker view has 2 buttons "Done" and "Cancel".

You mean 2 Text ?
Is it SwiftUI ?

When user press Done or Cancel, a gray rounded rect popup view(with text "Done" or "Cancel" which user pressed) appeared and disappeared soon like toast message.

Could you show the full code so that we can try to reproduce ?

I cannot reproduce this phenomenon.
Here is my customer's clip.
Code Block language
https://drive.google.com/file/d/1lr4T0G6L4cVyRMpgygdhDYg52crnTOvL/view?usp=sharing


Cancel button has only code like this
Code Block swift
@objc func cancelPushed(_ sender: UIBarButtonItem) {
dismiss()
}
func dismiss(){
UIView.animate(withDuration: 0.2,
animations: {
self.alpha = 0.0
},
completion: {_ in
self.removeFromSuperview()
})
}


Thanks.
Who is self here ?
Could you show more code ?

I guess that removing the animation would solve the problem, but that's not a perfect solution.
self is a custom class made with uiview.

Code Block
class BNPickerView: UIView

UIPickerView is declared inside this UIView.
So when function cancelPushed of UIPickerView is called, UIView will be removed by dismiss.
Would you mind showing the complete code for BNPickerView ?
Thank you Claude31 for your attention.
Here is full code of BNPickerView.

Code Block swift
//
// BNPickerView.swift
//
//
import UIKit
class BNPickerView: UIView {
enum doneMode: Int {
case done = 0
case save = 1
}
var doneStyle: doneMode = .done
let picker: UIPickerView = UIPickerView(forAutoLayout: ())
let toolbar = UIToolbar(forAutoLayout: ())
let doneButton: UIBarButtonItem = UIBarButtonItem(barButtonSystemItem: .done, target: self, action: #selector(donePushed(_:)))
let saveButton: UIBarButtonItem = UIBarButtonItem(barButtonSystemItem: .save, target: self, action: #selector(donePushed(_:)))
let cancelButton: UIBarButtonItem = UIBarButtonItem(barButtonSystemItem: .cancel, target: self, action: #selector(cancelPushed(_:)))
let backgroundView: UIView = UIView(forAutoLayout: ())
let toggle: BNToggleView = BNToggleView(frame: CGRect(x: 0, y: 0, width: 151, height: 32))
var data:[[String]] = [[]]
var doneResultHandler:([String],[Int])->() = {_,_ in }
func setData(data:[[String]], doneResultHandler:@escaping ([String],[Int])->()){
self.parentViewController()?.view.endEditing(true)
self.data = data
self.doneResultHandler = doneResultHandler
backgroundView.isUserInteractionEnabled = true
backgroundView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(dismissView(sender:))))
self.picker.dataSource = self
self.picker.delegate = self
self.addSubview(backgroundView)
backgroundView.autoPinEdge(toSuperviewEdge: .top)
backgroundView.autoPinEdge(toSuperviewEdge: .left)
backgroundView.autoPinEdge(toSuperviewEdge: .right)
backgroundView.backgroundColor = UIColor.black.withAlphaComponent(0.7)
self.addSubview(toolbar)
toolbar.autoPinEdge(toSuperviewEdge: .left)
toolbar.autoPinEdge(toSuperviewEdge: .right)
let done = self.doneStyle == .done ? doneButton : saveButton
toolbar.setItems([cancelButton, UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil), done], animated: true)
toolbar.addSubview(toggle)
toggle.configureForAutoLayout()
toggle.autoAlignAxis(toSuperviewAxis: .horizontal)
toggle.autoAlignAxis(toSuperviewAxis: .vertical)
toggle.autoSetDimensions(to: CGSize(width: 151, height: 32))
toggle.alpha = 0
self.addSubview(picker)
picker.autoPinEdge(toSuperviewSafeArea: .left)
picker.autoPinEdge(toSuperviewSafeArea: .right)
picker.autoPinEdge(toSuperviewEdge: .bottom)
picker.autoSetDimension(.height, toSize: 315)
picker.backgroundColor = UIColor.white
toolbar.autoPinEdge(.bottom, to: .top, of: picker)
backgroundView.autoPinEdge(.bottom, to: .top, of: toolbar)
}
override func draw(_ rect: CGRect) {
self.alpha = 0.0
UIView.animate(withDuration: 0.2,
animations: {
self.alpha = 1.0
},
completion: {_ in
})
}
@objc func donePushed(_ sender: UIBarButtonItem) {
var out:[String] = []
var outIndex:[Int] = []
for index in 0..<data.count{
outIndex.append(picker.selectedRow(inComponent: index))
out.append(data[index][picker.selectedRow(inComponent: index)])
}
self.doneResultHandler(out,outIndex)
dismiss()
return
}
@objc func cancelPushed(_ sender: UIBarButtonItem) {
dismiss()
}
@objc func dismissView(sender:UIView){
dismiss()
}
func dismiss(){
UIView.animate(withDuration: 0.2,
animations: {
self.alpha = 0.0
},
completion: {_ in
self.removeFromSuperview()
})
}
}
extension BNPickerView: UIPickerViewDataSource{
func numberOfComponents(in pickerView: UIPickerView) -> Int {
return data.count
}
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return data[component].count
}
}
extension BNPickerView: UIPickerViewDelegate{
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
return data[component][row]
}
func pickerView(_ pickerView: UIPickerView, rowHeightForComponent component: Int) -> CGFloat {
return 40
}
}


Why do you draw with animation ? What do you expect from it ?
Code Block
override func draw(_ rect: CGRect) {
self.alpha = 0.0
UIView.animate(withDuration: 0.2,
animations: {
self.alpha = 1.0
},
completion: {_ in
})
}

Try removing this animation which may be conflicting with other animations.
Thank you Claude31.
I'll try your suggestion.
But, I cannot confirm your suggestion will work.
Because I cannot reproduce this phenomenon on my iPhone.

Thank you.
UIPickerView button not worked
 
 
Q