- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//frame for the slider
CGRect myFrame = CGRectMake(60.0f, 10.0f, 250.0f, 25.0f);
//create and initialize the slider
mySlider = [[UISlider alloc] initWithFrame:myFrame];
//set the minimum value
self.mySlider.minimumValue = 0.0f;
//set the maximum value
self.mySlider.maximumValue = 100.0f;
//set the initial value
self.mySlider.value = 25.0f;
//set this to true if you want the changes in the sliders value
//to generate continuous update events
[self.mySlider setContinuous:true];
//attach action so that you can listen for changes in value
[self.mySlider addTarget:self action:@selector(getSliderValue:) forControlEvents:UIControlEventValueChanged];
//add the slider to the view
[selectedView addSubview:self.mySlider];
//move the origin for the Step Slider
myFrame.origin.y += myFrame.size.height + 20.0f;
self.myStepSlider = [[UISlider alloc] initWithFrame:myFrame];
self.myStepSlider.minimumValue = 0.0f;
self.myStepSlider.maximumValue = 100.0f;
self.myStepSlider.value = 30.0f;
[self.myStepSlider setContinuous:false];
[self.myStepSlider addTarget:self action:@selector(getSliderValue:) forControlEvents:UIControlEventValueChanged];
[selectedView addSubview:self.myStepSlider];
[cell.containter addSubview:selectedView];
}
- (void) getSliderValue:(UISlider *)paramSender{
//if this is my Step Slider then change the value
if ([paramSender isEqual:self.myStepSlider]){
float newValue = paramSender.value /10;
paramSender.value = floor(newValue) * 10;
}
NSLog(@"Current value of slider is %f", paramSender.value);
}
答案 0 :(得分:0)
在创建滑块时,不要在didSelectRowAtIndexPath
中添加滑块:
也可以在下次更彻底地解释你的问题。