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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:30:27+00:00 2026-06-10T06:30:27+00:00

Am new to iOS and Xcode. Am working with a simple calculator. I have

  • 0

Am new to iOS and Xcode. Am working with a simple calculator. I have a table view in which i added 30 textFields through code. I assign them tags.

Then i made the keyboard for textField of the NumPad type. For doing so i needed to dismiss the keyboard using a toolbar.

But when i run the program the textField with the last tag is dismis the keyboard while the others don’t do. I guess when i mention textField in my code it assigns textField of last tag.

My code is given.

for (int i = 0; i < 30; i++) {    
    mainTextField = [[UITextField alloc] initWithFrame:CGRectMake(20, (80 + (i * 60)), 280, 30)];        
    mainTextField.borderStyle = UITextBorderStyleRoundedRect;
    mainTextField.textColor = [UIColor blackColor]; 
    mainTextField.font = [UIFont systemFontOfSize:17.0]; 
    mainTextField.backgroundColor = [UIColor whiteColor]; 
    mainTextField.autocorrectionType = UITextAutocorrectionTypeNo;   
    mainTextField.backgroundColor = [UIColor clearColor];
    mainTextField.keyboardType = UIKeyboardTypeNumberPad;
    mainTextField.keyboardType=UIKeyboardTypeDecimalPad;
    mainTextField.returnKeyType = UIReturnKeyDone;  
    mainTextField.tag= i+1;
    mainTextField.delegate=self;

       [self->mainTableView  addSubview:mainTextField];

       self. numberToolbar = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, 320, 50)];
       self. numberToolbar.barStyle = UIBarStyleBlackOpaque;
       self. numberToolbar.items = [NSArray arrayWithObjects:
                               [[UIBarButtonItem alloc]initWithTitle:@"Cancel" style:UIBarButtonItemStyleBordered target:self action:@selector(cancelNumberPad)],
                               [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil],
                               [[UIBarButtonItem alloc]initWithTitle:@"Done" style:UIBarButtonItemStyleDone target:self action:@selector(doneWithNumberPad)],
                               nil];
       [self.numberToolbar setTag:i+1];
        [self.numberToolbar sizeToFit];

        mainTextField.inputAccessoryView = numberToolbar;


        mainTextField.clearButtonMode = UITextFieldViewModeWhileEditing;

    mainLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 55+(i*60), 280, 18)];
    mainLabel.backgroundColor = [UIColor clearColor];
    mainLabel.textAlignment = UITextAlignmentLeft;
    mainLabel.tag= i+1;


    {
        switch ([mainLabel tag]) {
            case 1:
                mainLabel.text=[ passedValue objectAtIndex:0];
                break;
            case 2:
                mainLabel.text=[ passedValue objectAtIndex:1];
                break;
            case 3:
                mainLabel.text=[ passedValue objectAtIndex:2];
                break;
            case 4:
                mainLabel.text=[ passedValue objectAtIndex:3]; 
                break;
            case 5:
                 mainLabel.text=[ passedValue objectAtIndex:4];  
                break;
            case 6:
                mainLabel.text=[ passedValue objectAtIndex:5]; 
                break;
            case 7:
                mainLabel.text=[ passedValue objectAtIndex:6]; 
                break;
            case 8:
                mainLabel.text=[ passedValue objectAtIndex:7]; 
                break;
            case 9:
                 mainLabel.text=[ passedValue objectAtIndex:8]; 
                break;
            case 10:
                 mainLabel.text=[ passedValue objectAtIndex:10]; 
                break;
            case 11:
                 mainLabel.text=[ passedValue objectAtIndex:11]; 
                break;
            case 12:
                mainLabel.text=[ passedValue objectAtIndex:12]; 
                break;
            case 13:
                 mainLabel.text=[ passedValue objectAtIndex:13]; 
                break;
            case 14:
                mainLabel.text=[ passedValue objectAtIndex:14]; 
                break;
            case 15:
                 mainLabel.text=[ passedValue objectAtIndex:15]; 
                break;
            case 16:
                 mainLabel.text=[ passedValue objectAtIndex:16]; 
                break;
            case 17:
                 mainLabel.text=[ passedValue objectAtIndex:17]; 
                break;
            case 18:
                 mainLabel.text=[ passedValue objectAtIndex:18];    
                break;
            case 19:
                 mainLabel.text=[ passedValue objectAtIndex:19]; 
                break;
            case 20:
                 mainLabel.text=[ passedValue objectAtIndex:20]; 
                break;
            case 21:
                 mainLabel.text=[ passedValue objectAtIndex:21]; 
                break;
            case 22:
                mainLabel.text=[ passedValue objectAtIndex:22]; 
                break;
            case 23:
               mainLabel.text=[ passedValue objectAtIndex:23]; 
                break;
            case 24:
               mainLabel.text=[ passedValue objectAtIndex:24]; 
                break;
            case 25:
                 mainLabel.text=[ passedValue objectAtIndex:25]; 
                break;
            case 26:
                mainLabel.text=[ passedValue objectAtIndex:26]; 
                break;
            case 27:
                mainLabel.text=[ passedValue objectAtIndex:27]; 
                break;
            case 28:
                 mainLabel.text=[ passedValue objectAtIndex:28]; 
                break;
            case 29:
                 mainLabel.text=[ passedValue objectAtIndex:29]; 
                break;

            default:
                break;
        }



    [self->mainTableView addSubview:mainLabel];
    [self configureView];
  • 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-10T06:30:28+00:00Added an answer on June 10, 2026 at 6:30 am

    There are a couple of things wrong with this code.

    First of all, this is not how you create a table with 30 text fields. Instead, you use a UITableView, set it’s delegate and dataSource to your view controller and implement the required methods. Among others tableView:numberOfRowsInSection: where you’ll return 30. Then in tableView:cellForRowAtIndexPath: you create a cell, put one text field into it and return the cell. There are tons of tutorials on the internet about how to set up a table view like this and you can also read the documentation by Apple. You almost never add any additional views to the tableView itself.

    self->tableView is just wrong. The -> notation is used (among others) in C when you want to dereference a pointer to a struct and access or set one of it’s variables. You don’t use it with Objective-C objects. Simply write self.tableView. This should work if you declared your property correctly.

    That switch block is unnecessary. Why don’t you do this instead:

    mainLabel.text = [passedValue objectAtIndex[mainLabel tag]-1];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am completely new to Xcode and iOS developing in general. Basically I have
So I'm working through the code in this tutorial which has a small button
I'm new to iOS & Xcode development. I have created a new story board
(iOS 5.1, XCode 4.4) In a project I am working on, I have two
xcode 4.2 ios 5 single view template I am very new to this ios
I am new to iOS 5. Currently working with xcode 4.2,Base sdk iOS 5.0,Apple
I'm working on my first somewhat serious iOS app and I'm new to Xcode,
So I am very new to xcode and iOS and just getting use to
I'm new to Xcode and programming for iOS, so I might not get what
I'm a new iOS programming and I'm developing a simple iPhone game that needs

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.