I want to display picker when my button is tapped I have this view that a I re-use (view contains a textField and button)
I set the action to display the picker in the viewDidLoad
InputViewController:UIViewController, UIPickerViewDelegate, UIPickerViewDataSource { var picker = UIPickerView()override func viewDidLoad() { super.viewDidLoad() self.innerButton.addTarget(self, action: #selector(setPicker(sender:)), for: .touchUpInside)}@objc func setPicker(sender:UIButton){ let viewSizeWidth = UIScreen.main.bounds.size.width picker = UIPickerView.init() picker.delegate = self picker.dataSource = self picker.backgroundColor = UIColor.white picker.setValue(UIColor.black, forKey: "textColor") picker.autoresizingMask = .flexibleWidth picker.contentMode = .center picker.frame = CGRect.init(origin: CGPoint.zero , size: CGSize(width: viewSizeWidth, height: 400)) self.view.addSubview(picker)}}
Actually this happens when I tapped my button:
(Button and textField disappears and picker looks squashed)My expected output is display picker with button and set selected raw in my textfield, what is missing in mi code ?