且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

UIPickerView 和 UITextField 从 UIPickerView 获取值

更新时间:2023-02-02 13:46:28

参见 选择器视图委托协议.实现这个方法:

See the picker view delegate protocol. Implement this method:

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component

在这里,您可以从模型中获取适当的值并更新您的文本字段.

In here, you can get the appropriate value from the model and update your text field.

要确定哪个是当前文本字段,您需要找出哪个文本字段是第一响应者.

To work out which is the current text field, you'd need to find out which of the text fields is the first responder.

拥有 IBOutletCollection 或数组中的所有文本字段,遍历它们并找到第一响应者.

Have all of the text fields in an IBOutletCollection or array, iterate through them and find the one which is first responder.

或者,如果您有文本字段委托,您可以在 didBeginEditing 委托方法中为当前文本字段设置一个 ivar,并在上面的选择器视图委托方法中使用它.

Or, if you have text field delegates, you can set an ivar for the current text field in the didBeginEditing delegate method, and use this in the picker view delegate method above.