0

我有一个视图控制器,它显示各种UITextfields 来编辑信息。一方面UITextfield,我需要一个选择轮来选择预定义的状态。

问题是我没有足够的空间来集成选择轮,是否有可能仅在选择文本框时才出现?

4

3 回答 3

2

您可以将 设置UIPickerViewUITextField's inputView

这将确保选择器在文本字段获得焦点时自动显示,并在丢失时隐藏它。

例如

myTextField.inputView = self.myPickerView;

请参阅有关此属性的文档。

于 2013-01-30T15:00:27.660 回答
1

你需要调用你的 UIPicker(BOOL)textFieldShouldBeginEditing:

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


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

查看 如何在选择 UITextField 时显示 UIPickerView

于 2013-01-30T14:59:28.197 回答
1

假设您的“选择器轮”是一个 UIView,只需将您的控制器连接为 UITextField 的委托并实现以下内容:

- (void)textFieldDidBeginEditing:(UITextField *)textField {
   self.pickerWheel.hidden = NO;
}
于 2013-01-30T14:53:15.927 回答