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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T21:16:15+00:00 2026-06-05T21:16:15+00:00

I have a UIStepper control that i created programmaticly in my UITableViewCell . I

  • 0

I have a UIStepper control that i created programmaticly in my UITableViewCell. I also created a UILabel programmaticly for the cell. whats happening is that the stepper when pressed is accessing a UILabel located in a different cell i.e index path 1 and not 0. here is the code.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ 
...
 //---------UIStepper Creation-------------------//

stepper = [[UIStepper alloc]init];
[stepper setFrame:CGRectMake(220.0f, 65.0f, 0.0f, 0.0f)];
[stepper setTag: indexPath.row];
[stepper addTarget:self action:@selector(stepperPressed:) forControlEvents:UIControlEventValueChanged];

stepperLabel = [[UILabel alloc] init];
[stepperLabel setFrame:CGRectMake(105,70, 20, 20)];
[stepperLabel setTextColor:[UIColor whiteColor]];
[stepperLabel setBackgroundColor:[UIColor clearColor]];
[stepperLabel setTag:stepper.tag];
[stepperLabel setText:[NSString stringWithFormat: @"%d", (int) [stepper value]]];
stepperLabel.lineBreakMode = UILineBreakModeWordWrap;
stepperLabel.numberOfLines = 1;//Dynamic

//Set min and max
[stepper setMinimumValue:0];
[stepper setMaximumValue:4];
// Value wraps around from minimum to maximum
[stepper setWraps:YES];
[stepper setContinuous:NO];

// To change the increment value for each step

...
[cell addSubview:stepperLabel];
[cell addSubview:stepper];
return cell;

and here is where i need the action to be performed

-(void) stepperPressed:(UIStepper *)sender{
NSIndexPath *indexPath = [self.tableView indexPathForCell:(UITableViewCell *)[sender superview]];
int row = indexPath.row;
NSLog(@"stepper is in row %d",row);
NSLog(@"stepperLabel is in row %d",stepperLabel.tag);
double value = [sender value];
if(sender.tag ==row){
  [stepperLabel setText:[NSString stringWithFormat: @"%d", (int) value]];
}
}

seriously need some help guys

  • 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-05T21:16:18+00:00Added an answer on June 5, 2026 at 9:16 pm

    stepperLabel will always point to the label at the last Cell you created in cellForRowAtIndexPath.
    So you can’t use it this way.

    Edited Answer:

    - (void)viewDidLoad {
        [super viewDidLoad];
        valueArray=[[NSMutableArray alloc]initWithObjects:[NSNumber numberWithInt:0],[NSNumber numberWithInt:0],[NSNumber numberWithInt:0], nil]; //Array Count = 
    }
    -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
        static NSString *CellIdentifier = @"Cell";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil) {
           cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    
            UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10.0f, 10.0f, 100.0f, 21.0f)];
           [cell addSubview:label];
           [label setTag:456];
    
           UIStepper *stepper = [[UIStepper alloc]initWithFrame:CGRectMake(110.0f, 10.0f, 20.0f, 20.0f)]; 
           [cell addSubview:stepper];
           [stepper setTag:123];
           [stepper addTarget:self action:@selector(stepperChanged:) forControlEvents:UIControlEventValueChanged];        
       }
       [cell setTag:indexPath.row];
       int count = [[valueArray objectAtIndex:indexPath.row] intValue];
    
       [(UIStepper*)[cell viewWithTag:123] setValue:count];
       [(UILabel*)[cell viewWithTag:456] setText:[NSString stringWithFormat:@"%@: %d", @"Stepper", count]];
        return cell;
    }
    - (void)stepperChanged:(UIStepper*)sender {
        int row = [sender.superview tag];
        int value = (int)[sender value];
        NSLog(@"Stepper%d = %d", row,value);
    
        [valueArray replaceObjectAtIndex:row withObject:[NSNumber numberWithInt:value]];
    
        [(UILabel*)[(UITableViewCell *)sender.superview viewWithTag:456] setText:[NSString stringWithFormat:@"%@: %d", @"Stepper", value]];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my app I have custom UITableViewCell , and I have UIStepper and UILabel
Have a simple contact us XPage created. Have server side validation in place that
Have an app that can use tts to read text messages. It can also
Have a bunch of WCF REST services hosted on Azure that access a SQL
Have a look at one of my websites: moskah.com The problem is that it
I have got UIStepper in the piece of code which is generated using the
Have a network location that shows paths in the 8.3 short format. I need
Have data that has this kind of structure. Will be in ascending order by
Have data that has this kind of structure: $input = [ { animal: 'cat',
Have some dates in my local Oracle 11g database that are in this format:

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.