当选择 UITextField 时显示 UIPickerView
有没有人有一个在选择 UITextField 时显示 UIPickerView 的基本示例。
Does anyone have a basic example to display a UIPickerView when a UITextField was selected.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
最好的位置是在 NSTextField Delegate 方法中:
- (BOOL)textShouldBeginEditing:(NSText *)textObject
重写该方法以返回 NO 并调用选取器视图。返回 NO 将阻止键盘出现。
The best place to do so would be in the NSTextField Delegate method:
- (BOOL)textShouldBeginEditing:(NSText *)textObject
Override the method to return NO and instead evoke the picker view. Returning NO will prevent the keyboard from appearing.
我所做的是实现 TouchsEnded 事件。如果该事件发生在我的 UITextField 参数中,那么我会隐藏或显示 UIPickerView
What I did was implement touchesEnded event. If that event occurs in my UITextField parameters then I either hide or show the UIPickerView
http://tmblr.co/ZjkSZteCOUBS
我的博客中列出了代码和所有内容来准确执行此操作。但下面我列出了基本概念。
基本上,该解决方案涉及 github 上名为 ActionSheetPicker 的开源项目,并在
UITextFieldDelegate
上实现textFieldShouldBeginEditing
功能。您可以在那里关闭键盘并提供 UIPickerView。基本代码列于此处:编辑我知道这个问题不久前被问过,但觉得有必要提供更新的解决方案。
http://tmblr.co/ZjkSZteCOUBS
I have the code and everything laid out in my blog to do this exactly. But below, I have the basic concept laid out.
Basically the solution involves an opensource project called ActionSheetPicker on github, and implementing the function
textFieldShouldBeginEditing
on theUITextFieldDelegate
. You can dismiss the keyboard there and provide a UIPickerView instead. The basic code is listed here:EDIT I know this question was asked a while ago, but felt it was necessary to provide a more recent solution.