如何在uitextfield中显示pickerview而不是键盘? [英] how to show pickerview in uitextfield not the keyboard?

查看:151
本文介绍了如何在uitextfield中显示pickerview而不是键盘?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想显示一个UIPickerView成为UITextfield的FirstResponder而不是键盘,并在选择器视图中填写文本字段中的值。

I want to show a UIPickerView on becoming FirstResponder of a UITextfield not the keyboard and fill the value in text field form the picker view.

任何人都知道这个吗?

any one knows this?

推荐答案

编辑:在撰写本文时,这个答案是正确的。 Apple此后推出了 inputView 。 Mafonya 回答是您现在应该做的事情。

this answer was correct at the time of writing. Apple has since introduced inputView. Mafonya answer is what you should be doing nowadays.

It可以防止键盘弹出。将您的类设置为UITextField的委托: textField.delegate = self 并添加:< UITextFieldDelegate> 之后您的接口声明(在头文件中的{)之前。

It is possible to prevent the keyboard from popping up. Set your class to be the delegate of the UITextField: textField.delegate = self and add: <UITextFieldDelegate> after your interface declaration (before the {) in the header file.

现在实现 textFieldShouldBeginEditing:

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
    // Show UIPickerView

    return NO;
}

如果你想隐藏你的pickerView这个方法不起作用。你可以做的是创建UITextField的子类并覆盖 * trackingWithTouch:event:选择器并在那些中做你的魔术。您可能仍需要从 textFieldShouldBeginEditting:返回NO以防止键盘显示。

If you want to be able to hide your pickerView this method won't work. What you could do then is create subclass of UITextField and override the *trackingWithTouch:event: selectors and do your magic in those. You probably still need to return NO from textFieldShouldBeginEditting: to prevent the keyboard from showing.

这篇关于如何在uitextfield中显示pickerview而不是键盘?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆