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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T17:11:38+00:00 2026-05-29T17:11:38+00:00

How do I create and add multiple UITextField to my controller? I can create

  • 0

How do I create and add multiple UITextField to my controller?

I can create one, like this:

UITextField *tf = [[UITextField alloc] initWithFrame:CGRectMake(5,5,100,25)];
tf.borderStyle = UITextBorderStyleRoundedRect;
[tf setReturnKeyType:UIReturnKeyDefault];
[tf setEnablesReturnKeyAutomatically:YES];
[tf setDelegate:self];
[self.view addSubview:tf]

But do I need to do that for each UITextField?

Whats the best approach to template UI Controls?

  • 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-29T17:11:41+00:00Added an answer on May 29, 2026 at 5:11 pm

    Put it in a loop, offset each text field’s Y position and tag each text field:

    for (int i = ; i < numberOfTextFieldsNeeded; i++) {
        UITextField *tf = [[UITextField alloc] initWithFrame:CGRectMake(5, 5 + 35 * i ,100,25)]; // 10 px padding between each view
        tf.tag = i + 1; // tag it for future reference (+1 because tag is 0 by default which might create problems)
        tf.borderStyle = UITextBorderStyleRoundedRect;
        [tf setReturnKeyType:UIReturnKeyDefault];
        [tf setEnablesReturnKeyAutomatically:YES];
        [tf setDelegate:self];
        [self.view addSubview:tf]
        // don't forget to do [tf release]; if not using ARC
    }
    

    Then in delegate methods perform actions based on tag of the textField that called each delegate method. For example to switch to next text view when user taps return key:

    - (BOOL)textFieldShouldEndEditing:(UITextField *)textField
    {
        [textField resignFirstResponder];
        UITextField *nextTextField = [self.view viewWithTag:textField.tag + 1];
        [nextTextField becomeFirstResponder];
    }
    

    Keep in mind that sending messages to nil in Objective-C will not crash so it will be perfectly fine when user taps return key in last text field as UITextField *nextTextField = [self.view viewWithTag:textField.tag + 1]; will return nil, and calling becomeFirstResponder on nil will do nothing. But you can check if nextTextField is nil and do something else then, whatever you like.

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

Sidebar

Related Questions

Possible Duplicate: How to create a multiline UITextfield? How can I implement a multiple
If I create a UserControl and add some objects to it, how can I
I am working a project currently in which the user can add multiple news
I want to create a one to many relationship. My setup is something like:
is there a way to create/add multiple elements at once? In the following example
I want to create an action once, then add it to multiple sprites. For
I'd like to add multiple 'items' to the same cell using tables.LinkColumn . Something
I have a project where the user can add multiple files to a cart
I'm trying to add multiple categories to a Wordpress (3.3.1) post via XMLRPC. This
I have a for loop that creates multiple UIImageViews that I add to self.view

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.