JSON文字列を解析してUIを作成するデータドライブアプリを作成しようとしています。これを実装し、必要なコントロールを作成しました。割り当てられたタグに基づいて各コントロールを区別していますが、これは効率的な方法ではありません。UIControl を動的に作成する際に、名前 (次の例ではラベルとテキストフィールド以外) を UIControl に割り当てる方法はありますか?
NSMutableArray *myArray = [[NSMutableArray alloc] initWithCapacity: myArrayCount];
for ( loop = 0; loop< myArrayCount; loop++ ) {
NSString *propertyName = [NSString stringWithFormat:@"Label %d", loop];
[myArray addObject:propertyName];
CGRect labelFrame = CGRectMake(xLabel, yLabel, widthLabel, heightLabel);
UILabel *label = [[UILabel alloc] initWithFrame: labelFrame];
label.tag = loop;
[label setText:propertyName];
[label sizeToFit];
[self.view addSubview:label];
UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(xTextField, yTextField, widthTextField, heightTextField)];
textField.tag = loop;
textField.borderStyle = UITextBorderStyleRoundedRect;
textField.font = [UIFont systemFontOfSize:15];
textField.placeholder = @"Enter parameter value";
textField.autocorrectionType = UITextAutocorrectionTypeNo;
textField.keyboardType = UIKeyboardTypeDefault;
textField.returnKeyType = UIReturnKeyDone;
textField.clearButtonMode = UITextFieldViewModeWhileEditing;
textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
textField.returnKeyType = UIReturnKeyDone;
textField.delegate = self;
[self.view addSubview:textField];
yLabel = yLabel+yOffset;
yTextField = yTextField+yOffset;
}