I create programmatically 12 textfields using one method and I add a tag to each.
Below is the method that creates the textfields, this is called 12 times to create each of the textfields. This works.
textField = [[UITextField alloc] initWithFrame:CGRectMake(x, y, w, h)];
textField.borderStyle = UITextBorderStyleRoundedRect;
textField.font = [UIFont systemFontOfSize:15];
textField.placeholder = name;
[textField setTag:tag];
textField.autocorrectionType = UITextAutocorrectionTypeNo;
textField.keyboardType = UIKeyboardTypeDefault;
textField.returnKeyType = UIReturnKeyDone;
textField.clearButtonMode = UITextFieldViewModeWhileEditing;
textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
[self.view addSubview:textField];
My question is how do I set the text in each textfield or how do I access it using the tags.
I tried:
[textField.2 setText: [NSString stringWithFormat : @"HEY"]];
and that does not work.
It’s often a better idea to create an
NSArrayproperty that contains the text fields though.