Popup UIPicker when tapping on UITextField

為{幸葍}努か 提交于 2019-12-08 12:24:14

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!