我试图弄清楚如何将选定的UIPicker
值传递给UITextField
. 我已经创建了选择器和几个UItextFields
带有.tag
身份的选项UITextField
来将值放入其中,但是我只是不知道该怎么做。
这是我在UIPickerView
点击时使用的方法
// Do something with the selected row.
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
NSLog(@"You selected this: %@", [dataArray objectAtIndex: row]);
NSString *temp = [dataArray objectAtIndex:row]; // this contains the selected value from UIPickerView
NSLog(@"%@", temp);
// if (cutField.tag == 0) { // trying to pass the string to the correct UItextfield... or any UItextfield for that matter
cutField.text = temp;
// }
}
上述方法已执行,但 cutField 中从未设置值。我不知道如何确定应该更新哪一个,因为我不知道如何访问标签值。
这就是我分配标签值的方式UITextField
:
for (int i = 0; i < cutCount; i++)
{
//first one
cutField = [[UITextField alloc] initWithFrame:CGRectMake(((positions*i)-(20/2)+(positions/2)), 25, 20, 20)];
cutField.inputView = pickerView;
cutField.textColor = [UIColor colorWithRed:0/256.0 green:84/256.0 blue:129/256.0 alpha:1.0];
cutField.font = [UIFont fontWithName:@"Helvetica-Bold" size:25];
cutField.backgroundColor=[UIColor whiteColor];
[view addSubview:cutField];
cutField.tag = tagNumber;
tagNumber ++;
[columnArrayOfTextFields addObject:cutField]; // array of textfields
}