0

i want to code of UISlider Value Changed that time also UItableview detailTextLabel Value also be changed? see below Image.

enter image description here

when i am change slider value dynamically change of detailTextLabel of Alert Range ? also store when i am come back with this UIview that also represent old value of slider and detailTextLabel.

 UISlider *slider = [[UISlider alloc]initWithFrame:CGRectMake(45, 45, 290,20)];
    if(indexPath.row == 0)
    {
        NSString *sliderValue =[NSString stringWithFormat:@"%d KM",(int)[_defaults floatForKey:@"Slider"]];
        cell.detailTextLabel.text = sliderValue;
    }
    if(indexPath.row == 1)
    {

        slider.minimumValue = 5;
        slider.maximumValue = 20;
        slider.value =(int)[_defaults floatForKey:@"Slider"];
        cell.accessoryView = slider;

    }
    [slider addTarget:self action:@selector(sliderValueChanged:) forControlEvents:UIControlEventValueChanged];

}
cell.textLabel.backgroundColor = [UIColor clearColor];
//[_table reloadData];
return cell; }

-(void)sliderValueChanged:(id)sender
 {
UISlider *slider = sender;
[_defaults setFloat:slider.value forKey:@"Slider"];
//[_table reloadData];
 }

Thanks in Advance...

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Priyank Gandhi
  • 626
  • 2
  • 8
  • 21

2 Answers2

2

Call [self.tableView reloadData]; each time the slider moves. Ensure the value you want to be dynamic is a property and is set by the slider.

If you do not want to reload the entire tableView you can also reload the cell with this function:

- (void)reloadRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation

Check out this question for more help on reloadRowsAtIndexPaths: Reload specific UITableView cell in iOS

Community
  • 1
  • 1
John Riselvato
  • 12,854
  • 5
  • 62
  • 89
0

You should use addTarget for your UISlider. Everytime the events will be called, you can change the value inside your data model and reloadTable to show the changed value.

Have a look at this example

Community
  • 1
  • 1
Alex Cio
  • 6,014
  • 5
  • 44
  • 74