如何获得范围滑块中的最终值?

时间:2018-12-03 07:57:40

标签: ios objective-c rangeslider

我正在使用TT范围滑块(Double滑块)在我的应用中过滤价格,一切正常,但是当我的最终价格是某个价格(例如20)且没有选择滑块时,我单击“应用”按钮,最终价格为如果出现任何答案,滑块选项将变为0值。提前致谢。 我的代码

float price = [_filterpriceStr floatValue];

NSLog(@"%f",price);

if ([[GlobalVariables appVars].Apply isEqualToString:@"Apply"]) {

    float minimum = [[[NSUserDefaults standardUserDefaults]valueForKey:@"filtermin"] floatValue];
    float maxmum = [[[NSUserDefaults standardUserDefaults]valueForKey:@"filtermax"] floatValue];

    minValue = [[NSUserDefaults standardUserDefaults]valueForKey:@"filtermin"];
    maxValue = [[NSUserDefaults standardUserDefaults]valueForKey:@"filtermax"];

    //standard range slider
    self.rangeSlider.delegate = self;
    self.rangeSlider.minValue = 0;
    self.rangeSlider.maxValue = price;
    self.rangeSlider.step = price;

    self.rangeSlider.selectedMinimum = minimum;
    self.rangeSlider.selectedMaximum = maxmum;

    NSNumberFormatter *customFormatter = [[NSNumberFormatter alloc] init];
    customFormatter.positivePrefix = @"£";
    self.rangeSlider.numberFormatterOverride = customFormatter;
    self.rangeSlider.tintColorBetweenHandles = [UIColor colorWithRed:15.0f/255.0f green:201.0f/255.0f blue:218.0f/255.0f alpha:1.0f];

}
else
{
    float price = [_filterpriceStr floatValue];

    //standard rsnge slider
    self.rangeSlider.delegate = self;
    self.rangeSlider.minValue = 0;
    self.rangeSlider.maxValue = price;
    self.rangeSlider.selectedMinimum = 0;
    self.rangeSlider.selectedMaximum = price;

    NSNumberFormatter *customFormatter = [[NSNumberFormatter alloc] init];
    customFormatter.positivePrefix = @"£";
    self.rangeSlider.numberFormatterOverride = customFormatter;
    self.rangeSlider.tintColorBetweenHandles = [UIColor colorWithRed:15.0f/255.0f green:201.0f/255.0f blue:218.0f/255.0f alpha:1.0f];

}

单击“应用”按钮时

 [GlobalVariables appVars].PriceRange = @"PriceRange";


[[NSUserDefaults standardUserDefaults]setValue:minValue forKey:@"filtermin"];

[[NSUserDefaults standardUserDefaults]setValue:maxValue forKey:@"filtermax"];

[[NSUserDefaults standardUserDefaults]synchronize];

NSLog(@"%@",maxValue);

[self.navigationController popViewControllerAnimated:NO];

1 个答案:

答案 0 :(得分:3)

添加此委托方法,您将使用该方法获取最小和最大滑块值。

 -(void)rangeSlider:(TTRangeSlider *)sender didChangeSelectedMinimumValue:(float)selectedMinimum andMaximumValue:(float)selectedMaximum{

NSLog(@" Min Value: %.0f Max Value: %.0f", selectedMinimum, selectedMaximum);

    [[NSUserDefaults standardUserDefaults]setValue:selectedMinimum forKey:@"filtermin"];

    [[NSUserDefaults standardUserDefaults]setValue:selectedMaximum forKey:@"filtermax"];

 }