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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:19:08+00:00 2026-05-23T19:19:08+00:00

So, I have the slider adding UITextFields but it’s not updating/subtracting UITextField’s when selecting

  • 0

So, I have the slider adding UITextFields but it’s not updating/subtracting UITextField’s when selecting less than the previous Slider Value. Does [self.view addSubview:textField]; need to be outside of the for loop? Thanks in advance.

- (IBAction) sliderValueChanged:(UISlider *)sender {
float senderValue = [sender value];
int roundedValue = senderValue * 1;
ingredientLabel.text = [NSString stringWithFormat:@"%d", roundedValue];
int moveYBy = 35;
int baseY = 140;
for(int y = 0; y < roundedValue; y++){
    UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(20, baseY, 227, 31)];
    textField.text = [NSString stringWithFormat:@"%d", roundedValue];
    textField.borderStyle = UITextBorderStyleRoundedRect;
    baseY = baseY + moveYBy;
    [self.view addSubview:textField];
    [textField release];
    NSLog(@"Adding %d fields!", roundedValue);
}
NSLog(@"%d", roundedValue);
}
  • 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-23T19:19:09+00:00Added an answer on May 23, 2026 at 7:19 pm

    You are creating N text fields everytime the slider value changes (where n is the rounded value).

    Instead, you should make an NSMutableArray an iVar and store all the text fields there, when roundedValue is bigger than the number of text fields in that array, we add more. When it’s smaller, we remove some.

    (I’m using an iVar called textFieldsArray, and I also changed a little the way the y is calculated for the arrays)

    - (IBAction) sliderValueChanged:(UISlider *)sender {
        float senderValue = [sender value];
        int roundedValue = senderValue * 1;
        ingredientLabel.text = [NSString stringWithFormat:@"%d", roundedValue];
        for(int y = 0; y < roundedValue; y++){
            if(y > [textFieldsArray count]){
                UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(20, 140 + 35 * y, 227, 31)];
                textField.text = [NSString stringWithFormat:@"%d", roundedValue];
                textField.borderStyle = UITextBorderStyleRoundedRect;
                [self.view addSubview:textField];
                [textFieldsArray addObject:textField];
                [textField release];
                NSLog(@"Adding %d fields!", roundedValue);
            }
        }
        while([textFieldsArray count] > roundedValue){
            UITextField *textField = [textFieldsArray lastObject];
            [textField removeFromSuperview];
            [textFieldsArray removeLastObject];
        }
        NSLog(@"%d", roundedValue);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Coda slider on one webpage (hand-crafted, not using the plugin, but
i have one getJSON request which is returning proper values but its not adding
I have an slider animation but on clX.click event #close div hides before it
I have a slider with minimum value 0 and maximum value 1 . When
I have a slider with values ranging from 0 to 100. I want to
In my View I have a slider and a combobox . When I change
I have a StackPanel inside of a ScrollViewer. I have a slider that does
I am creating a portfolio page for m personal site. I have a slider
I am creating a portfolio page for m personal site. I have a slider
I'm trying to get the jQuery slider to have set values to slide to

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.