Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8194487
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T04:50:27+00:00 2026-06-07T04:50:27+00:00

I am trying to write data drive App where I parse json string to

  • 0

I am trying to write data drive App where I parse json string to create UI. I have implemented this and created required controls. I am differentiating each control based on the tag assigned to them which is not efficient way. Is there anyway to assign name(other than label and textfield in following example) to UIControl while creating it dynamically?

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;

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T04:50:28+00:00Added an answer on June 7, 2026 at 4:50 am

    Assuming you don’t want to use [self.view viewWithTag:tag] to retrieve your controls, one way to reference a dynamically created control by name would be to put it in an NSMutableDictionary with a dynamically generated key.

    So maybe something like (a modification of your code with some of the details elided):

    NSMutableDictionary *controlsDictionary = [[NSMutableDictionary alloc] init];
    for ( loop = 0;  loop< myArrayCount; loop++ ) {
    
    CGRect labelFrame = CGRectMake(xLabel, yLabel, widthLabel, heightLabel);
    UILabel *label = [[UILabel alloc] initWithFrame: labelFrame];
    [controlsDictionary setObject:label forKey:[NSString stringWithFormat:@"label%d", loop]];
    
    UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(xTextField, yTextField, widthTextField, heightTextField)];
    [controlsDictionary setObject:label forKey:[NSString stringWithFormat:@"textField%d", loop]];
    
    yLabel = yLabel+yOffset; 
    yTextField = yTextField+yOffset;
    
    }
    

    Then you can retrieve the controls via statements like [controlsDictionary objectForKey:@"label1"]

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to write a python script that takes record data like this
I'm trying to write huge amounts of data onto my SSD(solid state drive). And
I am trying to write data stored in a binary file using turbo C++.
I am trying to write some data from these vectors onto text files. When
I am trying to write my spatial data from a table to a file.
I am trying write a function that generates simulated data but if the simulated
I want to write data into the file in binary form. I was trying
I am trying to write an application that adds data to an exsiting spreadsheet
I am trying to write a simple program in C# that will read data
I am trying to write the query for existing table data. TABLE_A and TABLE_B

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.