UIPicker
選択した値をに渡す方法を理解しようとしていUITextField
ます。私はピッカーを作成し、値を入れるIDをいくつか作成しましたが、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
}