Programmatically Create and Show UIPickerView

妖精的绣舞 提交于 2019-12-04 05:39:48

I found the problem-the code for assigning the input view doesn't include self. It should read

self.textField.inputView = picker

I was having the same problem trying to get the picker view to show up when clicking in the textfield. My issue was that for some reason my iOS simulator had the "Connect Hardware Keyboard" checked. In the iOS menu go to Hardware -> Keyboard and make sure "Connect Hardware Keyboard" is unchecked. Feels dumb now not noticing any keyboard was popping up in the app for several hours but hopefully this will help save someone else the frustration.

Just wanted to add an edit: In the iOS simulator you can try toggling the software keyboard (command+K) This worked for me as well in this case and allowed me to keep the hardware keyboard connected. Just something to check quickly before assuming your code is incorrect.

Louis Zhu

I'm not sure why you cannot see the picker. But it's a wrong way.

To create an instance using:

 picker = UIPickerView.alloc()

In Swift:

you should use:

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