Show UIPickerView like a keyboard, without UITextField

后端 未结 6 950
长发绾君心
长发绾君心 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:56

    A better option is still to use the UITextField. You don't have to actually show it on screen. Just put it in a 0x0 UIView so that it is not visible, set it's inputView to your UIPickerView and call becomeFirstResponder on it to show the picker and resignFirstResponder to hide it.

    It is convenient to have a UIView subclass that implements all of that along with UIPickerViewDelegate and UIPickerViewDataSource methods.

提交回复
热议问题