没有人有一个基本的例子来显示UIPickerView,当UITextField被选中时。当UITextField被选中时显示UIPickerView
回答
我做的是实现touchesEnded事件。如果我的UITextField参数发生该事件的话,我隐藏或显示UIPickerView
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [[event allTouches] anyObject];
if (CGRectContainsPoint([self.textField frame], [touch locationInView:self.view]))
{
//Want to show or hide UIPickerView
if(pickerView)
{
submitButton.hidden = !submitButton.hidden;
pickerView.hidden = !pickerView.hidden;
}
}
}
这样做将在委托的NSTextField方法最好的地方:
- (BOOL)textShouldBeginEditing:(NSText *)textObject
重写为返回NO,而是唤起选择器视图的方法。返回NO将阻止键盘出现。
我在我的博客上正好做到这一点奠定了代码和一切。但在下面,我列出了基本概念。
基本上解决方案涉及一个名为ActionSheetPicker的开源项目在github上,并在UITextFieldDelegate
上实现textFieldShouldBeginEditing
功能。您可以在那里关闭键盘并提供一个UIPickerView。基本的代码如下所示:
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
// We are now showing the UIPickerViewer instead
// Close the keypad if it is showing
[self.superview endEditing:YES];
// Function to show the picker view
[self showPickerViewer :array :pickerTitle];
// Return no so that no cursor is shown in the text box
return NO;
}
编辑我知道这个问题被问前一段时间,但认为有必要提供一个更近的解决方案。
当您评论时正在更新答案的过程中:) – KVISH 2012-11-19 20:05:40
优秀;谢谢! – 2012-11-19 20:10:15
- 1. 编辑UITextField时显示UIPickerView
- 2. 当单元格被选中时显示UIPickerView
- 3. 当我打开我的UITextField时,如何显示UIPickerView?
- 4. 当用户选择UITextField时显示UIPicker
- 5. 当UITextField被选中时移动UIView
- 6. UITextField显示UIPickerView在xcode 4.3.2使用textField.inputView
- 7. 当UITextField触及时显示子视图
- 8. 的UITextField和UIPickerView
- 9. UIPickerView和UITextField从UIPickerView中获取值
- 10. 当复选框被选中时,显示加载器微调器
- 11. 当复选框被选中时显示表格行
- 12. 当有一个复选框被选中时,显示paneloverlaylay
- 13. 当复选框被选中时显示特定的列
- 14. 显示只有当它被选中
- 15. UITextField与UITableViewCell中的UIPickerView?
- 16. 显示UIPickerView文本字段被选中,然后在选中后隐藏
- 17. UIPickerView不显示
- 18. 显示UIPickerView像键盘一样,没有UITextField
- 19. 的UITextField inputview弹出UIPickerView显示问号pickerview
- 20. 当用户点击UITextfield时,以编程方式实现UIPickerView
- 21. 如何在UITableView中选择行时显示UIPickerView?
- 22. 当图像被选中时显示预览div
- 23. 当复选框被选中/取消选中时如何隐藏/显示内容?
- 24. 我如何使uipickerview与多行选择和显示在uitextfield iphone中选择的选项?
- 25. 当我在swift中点击UITextField时,为什么不显示UIKeyboard?
- 26. 当显示键盘时将UITextField滚动到视图中
- 27. UIPickerView我如何显示没有选择?
- 28. 显示UIPickerView与选定的行
- 29. UIPickerView只显示questionmarks
- 30. UIPickerView不会显示
我认为这应该是: - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField – Kurt 2011-11-08 17:26:45
你是对的。我得到了错误的API。 – TechZen 2011-11-08 20:31:25