Show UIPickerView like a keyboard, without UITextField

后端 未结 6 949
长发绾君心
长发绾君心 2021-02-05 15:56

I\'m looking for a way to present a UIPickerView when the user taps on a UIBarButtonItem. Imagine a filter for the table view results.

I know I

6条回答
  •  情话喂你
    2021-02-05 16:46

    Attach a UIPickerView as the inputView of a 0-sized UITextField that you have added to your view.

            let picker = UIPickerView()
            picker.dataSource = self
            picker.delegate = self
    
            let dummy = UITextField(frame: CGRectZero)
            view.addSubview(dummy)
    
            dummy.inputView = picker
            dummy.becomeFirstResponder()
    

提交回复
热议问题