[英]Misuse of UITextField.inputView to get similar popup behavior of keyboard
I often want to put my own things in the same place the keyboard pops up, but for my own controls... such as putting a UIDatePicker there, or a custom UIPickerView, or whatever. 我经常想将自己的东西放在弹出键盘的相同位置,但是要使用自己的控件……例如在其中放置UIDatePicker或自定义UIPickerView或其他内容。
I came up with a clumsy way of getting this behavior by having a dummy UITextField and putting my custom view in its inputView property. 我想出了一种笨拙的方式来获得此行为,方法是使用虚拟UITextField并将自定义视图放入其inputView属性中。 Then when the user clicks on my item, I just trigger off the UITextField to display the view I've assigned to the inputView.
然后,当用户单击我的项目时,我只需触发UITextField即可显示我已分配给inputView的视图。
Then I got to wondering if there was a better less kludgey way to do this. 然后我想知道是否有更好的省时方法来做到这一点。 I found this article Show UIPickerView like a keyboard, without UITextField where several people recommend the same thing I do.
我发现这篇文章像键盘一样显示UIPickerView,没有UITextField ,几个人推荐我做同样的事情。
My question is this. 我的问题是这个。 Is it common to (mis)use the UITextField in this manner?
以这种方式(错误)使用UITextField是常见的吗?
Many times you will face a UITextfield that you would want to populate through a custom control other than the standrd keyboard. 很多时候,您将遇到要通过除标准键盘以外的自定义控件填充的UITextfield。 Thus the inputView method was declared and can be used.
因此,inputView方法已声明并可以使用。
What is recommended: 推荐什么:
1- if the UItextfield is normal, use the keybard (don't change the input view) 1-如果UItextfield正常,请使用键盘(不要更改输入视图)
2- if the value is numeric, show the numberpad in keyboard directly (textField.keyboardType = .numberPad) 2-如果值是数字,请直接在键盘上显示数字键盘(textField.keyboardType = .numberPad)
3- if your textField is a date then you set the input view as a date picker. 3-如果您的textField是日期,则将输入视图设置为日期选择器。
4- sometimes you need a UITextField where you need to choose between stuff. 4-有时您需要一个UITextField,您需要在其中进行选择。 Thus you develop your own custom UIPicker and set it as an input View.
因此,您可以开发自己的自定义UIPicker并将其设置为输入视图。
5- If what you are tring to achieve don't fall in all the above then you can do your own inputView and assign it. 5-如果您要实现的目标不属于上述所有内容,则可以执行自己的inputView并进行分配。
So in short don't be afraid, it is the normal thing to do! 总之,不要害怕,这是正常的事情!
Hope this helps! 希望这可以帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.