Domanda

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...

È stato utile?

Soluzione

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

Altri suggerimenti

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

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top