2

UIPicker選択した値をに渡す方法を理解しようとしていUITextFieldます。私はピッカーを作成し、値を入れるIDをいくつか作成しましたが、UItextFieldsその方法がわかりません.tagUITextField

これは、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
}
4

2 に答える 2

2

これらすべての「cutFields」を含むスーパービューへの参照を保持します。以下の例ではそれを呼び出していcontainerViewます。また、あなたの例ではタグとして「0」を使用しているため、以下でも使用しました。そのためにも変数を使用していると思いましたが。

次に使用します。

((UITextField *)[self.containerView viewWithTag:0]).text = temp;

または、複数の行にまたがって展開します。

UITextField* textField = (UITextField*) [self.containerView viewWithTag:0];
textField.text = temp;
于 2013-11-13T02:47:25.253 に答える
0

インスタンス化されたものがあるUITextFieldので、次のように試すことcutField.tagcutCount-1できます:

for (int i = 0; i < cutCount; i++) {
            //first one
            UITextField *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
        }
于 2013-11-13T02:46:43.907 に答える