问题
I need to display/show a Picker when a user taps on a textfield, I mean, it should appear a picker instead of a keyboard. Also, some sort of "done" button above the picker so the user clicks on it and the value from the picker is copied to the textfield and the picker is hidden again.
I've checked many tutorials from the web but haven't found anyone that can really help me.
I found a tutorial that pointed me in the right direction but I'm still missing to disappear the keyboard when clicking on the textfield. Dismissing UIPickerView with Done button on UIToolBar by @slev
Any ideas?
回答1:
If you're not targeting iOS versions older than 3.2, it's easy. You can either assign the UIPickerView as the inputView
property of the UITextField and the UIToolbar containing the 'done' button as the inputAccessoryView
, or you could make a single UIView that has both the picker and the toolbar as subviews and assign that as the intputView
(and leave inputAccessoryView
as nil). Either way, this will animate your picker in in place of the normal keyboard when the text field is activated.
More details on this are available in the documentation.
来源:https://stackoverflow.com/questions/6699392/popup-uipicker-when-tapping-on-uitextfield