Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/120.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 将UIPicker选定值插入UITextField_Ios_Tags_Uitextfield_Uipickerview - Fatal编程技术网

Ios 将UIPicker选定值插入UITextField

Ios 将UIPicker选定值插入UITextField,ios,tags,uitextfield,uipickerview,Ios,Tags,Uitextfield,Uipickerview,我正在尝试找出如何将选定的UIPicker值传递到UITextField。我用.tag创建了选择器和几个UITextField,以标识要将值放入哪个UITextField中,但是我不知道怎么做 这是我在点击UIPickerView时使用的方法 // Do something with the selected row. -(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSI

我正在尝试找出如何将选定的
UIPicker
值传递到
UITextField
。我用
.tag
创建了选择器和几个
UITextField
,以标识要将值放入哪个
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
}
for(int i=0;i
您刚刚实例化了一个
UITextField
,因此
cutField.tag
cutCount-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
        }
for(int i=0;i
保留对包含所有这些“剪切域”的superview的引用。在下面的示例中,我将其称为
containerView
。另外,您的示例使用“0”作为标记,因此我在下面也使用了它。虽然我假设你也会使用一个变量

然后使用:

((UITextField *)[self.containerView viewWithTag:0]).text = temp;
或分布在多条线路上:

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

我得到一个错误,在最后一个方括号中应为标识符。此代码包含和错误。。我自己想弄清楚,但很难找到任何参考online@HurkNburkS抱歉,我没有检查代码是否编译,我只是选错了范围括号
viewWithTag
仅返回基类
UIView
,因此在访问
text
属性之前必须强制转换。好的,这在将文本输入UItextfield时有效,但由于某些原因,它不会将文本输入到使用.tag定义的textfield中。