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

  • Home
  • SEARCH
  • 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 6146523
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:57:43+00:00 2026-05-23T18:57:43+00:00

Brand new to coding; been utilizing stackoverflow religiously for months; first time asking a

  • 0

Brand new to coding; been utilizing stackoverflow religiously for months; first time asking a question; please be gentle.

I’m trying to create a series of UITextFields programmatically using a for loop. The fields should have names like “pax1name”, “pax2name”, “pax3name”, etc.

The piece I’m missing is how to take a string and make it the name of a textField, changing the name of the textField each time the for-loop executes.

Here’s my code, but maybe I’m going about this the wrong way? Thank you in advance!

// set up the names textfields
for (int i = 0; i < 7; i++) {
    NSString *fieldName = [[NSString alloc] initWithFormat:@"pax%iname", (i + 1)];

    // I can't figure out what goes here to create a UITextField with the name of fieldName

    textField = [[UITextField alloc] initWithFrame:CGRectMake(15, (15 + (i * 40)), 400, 40)];
    textField.borderStyle = UITextBorderStyleRoundedRect;
    textField.font = [UIFont systemFontOfSize:15.0];
    textField.autocorrectionType = UITextAutocorrectionTypeNo;
    textField.clearButtonMode = UITextFieldViewModeWhileEditing;
    textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;

    [namesViewController addSubview: textField];

    [fieldName release];
    [textField release];
}
  • 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-05-23T18:57:43+00:00Added an answer on May 23, 2026 at 6:57 pm

    Normally you use the UIView property tag for that. Use [textField setTag:<youCustomTag>] in your loop to set the value, e.g. your variable i. Please note that tag expect an NSUInteger and not an NSString.

    To access the correct text field afterwards you’d call [[namesViewController view] viewWithTag:<yourCustomTag>].

    BUT, is it really necessary to create multiple text fields for your view controller? There might be a more elegant solution by creating just one single text field and setting the tag-property on demand when the user taps a row. I don’t know if that would work for you.

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

Sidebar

Related Questions

I'm brand new to MVC and, as a learning exercise, I'm trying to re-write
I am brand new to WCF, and have limited experience coding against web services.
I'm brand new to the MVC coding style and i'm having trouble deciding if
I'm brand new to C and am trying to learn how to take a
I am brand new to AS3 and I am trying to move all of
I am brand new to LINQ and am trying to query my DataSet with
I'm brand new to Ruby/Rails/RSpec, and hopefully this is a dumb/simple question. I'm currently
I’ve got a brand new Django project. I’ve added one minimal view function to
I've got my brand new VS2008 and decided to convert my main solution from
I'm not brand new to the concept of unit testing but at the same

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.