简体   繁体   English

选择器仅在选择时出现

[英]picker wheel that only appears when selected

I have a view controller that displays various UITextfield s to edit information. 我有一个视图控制器,它显示各种UITextfield来编辑信息。 For one UITextfield I need a picker wheel to select predefined statuses. 对于一个UITextfield我需要一个拨轮来选择预定义的状态。

Problem is I don't have enough space to integrate a picker wheel, is there a possibility to make it appear only when the text box is selected? 问题是我没有足够的空间来集成拾纸器拨轮,是否有可能使其仅在选中文本框时出现?

You could set the UIPickerView as the UITextField 's inputView . 您可以将UIPickerView设置为UITextFieldinputView

This will ensure that the picker is shown automatically when the text field gets focus, and hides it when lost. 这将确保在文本字段获得焦点时自动显示选择器,并在丢失时隐藏它。

Eg 例如

myTextField.inputView = self.myPickerView;

See the documentation on this property. 请参阅有关此属性的文档

Assuming your "picker wheel" is a UIView, just hook up your controller as the UITextField's delegate and implement the following: 假设您的“拨轮”是一个UIView,只需将您的控制器作为UITextField的委托进行连接并实现以下操作:

- (void)textFieldDidBeginEditing:(UITextField *)textField {
   self.pickerWheel.hidden = NO;
}

You need to call your UIPicker in (BOOL)textFieldShouldBeginEditing: 您需要在(BOOL)textFieldShouldBeginEditing:调用UIPicker (BOOL)textFieldShouldBeginEditing:

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{


    if (textField==self.yourtextfield) {
         //call your wheel in here 
    }
}

Look at How to Show UIPickerView when selecting UITextField 查看选择UITextField时如何显示UIPickerView

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM