识别循环生成的所有对象

时间:2012-05-26 18:40:51

标签: iphone loops uitextfield

这个问题与我之前提出的题为“Recognizing UIButton from a loop”的问题有点相关。

在这种情况下,我已经生成了一堆带循环的UITextFields。当其中一个的值发生变化时,我能够识别出它是哪个文本域。

但是,我想编辑生成的每个文本字段。具体来说,我从已编辑的一个文本字段中获取输入,并且我想根据识别的文本字段的输入和名称重新计算其他文本字段。

如何调用其他每个生成的未编辑文本字段?

/维拉德

2 个答案:

答案 0 :(得分:0)

将文本字段存储在数组中,然后当您想要更改值

[self.myTextFieldArray enumerateObjectsUsingBlock:^(UITextField *textField, NSUInteger idx, BOOL *stop){
    if (![textField isEqual:theTextFieldThatWasEdited])
        textField.text = @"whatever text you want";
}];

答案 1 :(得分:0)

由于您已经在使用标签,因此viewWithTag用于:

// Get a reference to the textfield with tag 3
UITextField *textField3 = (UITextField *)[self.view viewWithTag:3];

// Calculate your new value
float result = 4.32; // Calculate the value that you want the textfield with tag 3 to display

// Change the contents
textField3.text = [NSString stringWithFormat:@"%f", result];
相关问题