-2

如何在 UITableview 中添加多个 UIPickerViews 和文本字段,并使用不同的方法来管理 UIPickerViews?

4

1 回答 1

1

如果您需要在选择 textField 时显示 pickerView,则需要将 pickerView 作为 inputView 添加到 textField。

如果您有很多文本字段,最好在开始编辑文本字段时添加它。要确定应该显示哪个文本字段,选择器为每个文本字段添加标签。

- (void)textFieldDidBeginEditing:(UITextField *)textField{

   NSInteger tag = textField.tag;

   //Conditionally check which textField you want to show picker
   //Then call the method to add inputView to textField
   [self addInputViewToTextField:textField];

}

- (void)addInputViewToTextField:(UITextField *)textField{

    //Initialize pickerView 
    UIDatePicker *datePicker = ...

    textField.inputView = datePicker;

}

选择 textField 时显示 UIDatePicker的示例项目。

于 2013-05-12T21:22:44.623 回答