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 622253
In Process

The Archive Base Latest Questions

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

Is it possible to set the text field for a UITextField for multiple objects

  • 0

Is it possible to set the text field for a UITextField for multiple objects from within a loop using setValue:forKey:? I am a little confused if I should be somehow specifying “text” in the property name, or if I am missing something else?

// INTERFACE
@property(nonatomic, retain) IBOutlet UITextField *textFieldBit_01;
@property(nonatomic, retain) IBOutlet UITextField *textFieldBit_02;
@property(nonatomic, retain) IBOutlet UITextField *textFieldBit_03;
@property(nonatomic, retain) IBOutlet UITextField *textFieldBit_04;
@property(nonatomic, retain) IBOutlet UITextField *textFieldBit_05;

.

// IMPLEMENT
@synthesize textFieldBit_01;
@synthesize textFieldBit_02;
@synthesize textFieldBit_03;
@synthesize textFieldBit_04;
@synthesize textFieldBit_05;

for(unsigned int counter=1; counter<=5; counter++) {
    NSString *propertyName = [[NSString alloc] initWithFormat:@"textFieldBit_%02d.text",counter];
    NSString *propertyValue = [[NSString alloc] initWithFormat:@"%d", counter];

    [self setValue:propertyValue forKey:propertyName];
    [propertyName release];
    [propertyValue release];
}

EDIT_001

Maybe I should try and clarify my question a little: I am essentially trying to set the text on one of 5 UITextFields each time round a loop. I could use an “if” or “switch” but that looks a little like overkill. I thought maybe setValue:forKey: would let me do it by building a unique key during each iteration and using a single call.

if(counter == 1) [textFieldBit_01 setText:@"%02d", 1];
if(counter == 2) [textFieldBit_02 setText:@"%02d", 2];
if(counter == 3) [textFieldBit_03 setText:@"%02d", 3];
if(counter == 4) [textFieldBit_04 setText:@"%02d", 4];
if(counter == 5) [textFieldBit_05 setText:@"%02d", 5];

EDIT_002

NSString *propertyName = [[NSString alloc] initWithFormat:@"labelBit_%02d.text",counter];
NSString *propertyValue = [[NSString alloc] initWithFormat:@"%d", geoTag];      
[self setValue:propertyValue forKeyPath:propertyName];

Thank you for the answer, I now understand where I was going wrong, what I was using was setValue:forKey: when in a situation where I needed to access “labelBit_01.text” I should have been using setValue:forKeyPath:

gary

  • 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-13T18:57:54+00:00Added an answer on May 13, 2026 at 6:57 pm

    Try

    [self setValue:propertyValue forKeyPath:[propertyName stringByAppendingString:@".text"]];
    

    What this ends up giving you is this:

    self.textFieldBit_01.text = @"01";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

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.