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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:11:51+00:00 2026-05-22T19:11:51+00:00

I’m having a problem. I have a Custom UITableViewCel, the cell contains a slider

  • 0

I’m having a problem. I have a Custom UITableViewCel, the cell contains a slider which changes a value on a label on the cell. When clicking on the cell and then moving the table, the value replicates itself on another cell and then changes the value to a different cell, resetting it’s value to 0.

For demonstration purposes:

First setting the value

enter image description here

Clicking on a random cell then returns:

A totally different cell with the same data that was not put there.

enter image description here

And then when returning back to the cell where the value was first set:

enter image description here

The value is back to 0

Can anyone help me here:

My Slider value changed code;

labelSliderVal.text = [NSString stringWithFormat:@"%1.0f", sliderSlider.value];
if(sliderSlider.value < 30)
{
    self.backgroundColor = [UIColor redColor];
}
else if(sliderSlider.value > 60)
{
    self.backgroundColor = [UIColor greenColor];
} else {
    self.backgroundColor = [UIColor blueColor];
}

And my UITableViews didSelectRowAtIndexPath

Commented out

/*
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    // Navigation logic may go here. Create and push another view controller.
    /*
    <#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];
    // ...
    // Pass the selected object to the new view controller.
    [self.navigationController pushViewController:detailViewController animated:YES];
    [detailViewController release];

}*/

CellForRowAtIndexPath:

- (CustomCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"customCell";

    CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        NSArray *nibObjs = [[NSBundle mainBundle] loadNibNamed:@"CustomCellView" owner:nil options:nil];
        //cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];

        for(id currentObj in nibObjs)
        {
            if([currentObj isKindOfClass:[CustomCell class]])
            {
                cell = (CustomCell *)currentObj;
            }

        }
    }

    GradeToolAppDelegate * appDelegate = [UIApplication sharedApplication].delegate;
    Module *aModule = [appDelegate.modules4 objectAtIndex:indexPath.section];
    AssessmentDetail *anAssess = [aModule.assessmentDetails4 objectAtIndex:indexPath.row];

    cell.sliderSlider.tag = indexPath.row;  
    cell.labelAssessment.text = [NSString stringWithFormat:@"%@", anAssess.assessmentName4];
    cell.labelAssessmentType.text = [NSString stringWithFormat:@"%@", anAssess.assessmentType4];
    cell.labelWeighting.text = [NSString stringWithFormat:@"%@", anAssess.assessmentWeighting4];
    cell.labelDueDate.text = [NSString stringWithFormat:@"%@", anAssess.assessmentDueDate4];

    return cell;
}
  • 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-22T19:11:52+00:00Added an answer on May 22, 2026 at 7:11 pm

    Initialization

    NSMutableArray *results = [[NSMutableArray alloc] init];
    
    NSInteger numberOfSections = [myTableView numberOfSections];
    for ( int section = 0; section < numberOfSections ; section++ ) {
        NSInteger       numberOfRows   = [myTableView numberOfRowsInSection:section];
        NSMutableArray *sectionResults = [NSMutableArray array];
    
        [results addObject:sectionResults];
    
        for ( int row = 0; row < numberOfRows; row++ ) {
            [sectionResults addObject:[NSNumber numberWithFloat:0.0]];
        }
    }
    

    In tableView:cellForRowAtIndexPath:,

    ...
    NSArray *sectionResults = [results objectAtIndex:indexPath.section];
    NSNumber *number = [sectionResults objectAtIndex:indexPath.row];
    
    slider.value = [number floatValue];
    
    ...
    

    In sliderValueChanged:,

    - (void)sliderValueChanged:(UISlider *)slider {
        CustomCell *cell = (CustomCell *)slider.superview;
        NSIndexPath *indexPath = [myTableView indexPathForCell:cell];
        NSArray *sectionResults = [results objectAtIndex:indexPath.section];
    
        ...
        NSNumber *number = [NSNumber numberWithFloat:slider.value];
        cell.sliderValueLabel.text = [NSString stringWithFormat:@"%f", slider.value];
    
        [sectionResults replaceObjectAtIndex:indexPath.row withObject:number];
        ...
    }
    

    Code for totalForSection:,

    - (float) totalForSection:(NSInteger)sectionIndex {
        NSArray *sectionResults = [results objectAtIndex:sectionIndex];
        float result = 0.0;
    
        for (NSNumber *number in sectionResults) {
            result += [number floatValue];
        }
    
        return result;
    }
    
    - (float)sumTotal {
        float result = 0.0;
        NSinteger numberOfSections = [myTableView numberOfSections];
        for ( int i = 0; i < numberOfSections; i++ ) {
            result += [self totalForSection:i];
        }
    
        return result;
    }
    

    Initial Answer

    Well this is happening because of reusable cells. You will need to store the state of the contents and update the cell accordingly in tableView:cellForRowAtIndexPath:. On slider value change,

    - (void)sliderValueChanged:(UISlider *)slider {
        CustomCell *cell = (CustomCell *)slider.superview;
        NSIndexPath *indexPath = [myTableView indexPathForCell:cell];
    
        AssessmentDetail *anAssessment = [module.assessmentDetails4 objectAtIndex:indexPath.row];
        anAssessment.property = slider.value;
        cell.propertyLabel.text = [NSString stringWithFormat:@"%f", slider.value];
    }
    

    Now both the model and the label have been changed. So next time cell is reused, the label should get the right value.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I have just tried to save a simple *.rtf file with some websites and
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have a French site that I want to parse, but am running into
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but

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.