OStack程序员社区-中国程序员成长平台

标题: ios - 如何获得范围 slider 中的最终值? [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 14:59
标题: ios - 如何获得范围 slider 中的最终值?

我正在使用 TT 范围 slider (双 slider )在我的应用程序中过滤价格,一切正常,但是当我的最终价格是一些(例如 20)而没有选择 slider 时,我点击应用按钮最终价格是不来,如果有任何答案, slider 选项将变为 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 = @"riceRange";


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

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

[[NSUserDefaults standardUserDefaults]synchronize];

NSLog(@"%@",maxValue);

[self.navigationController popViewControllerAnimated:NO];



Best Answer-推荐答案


添加此委托(delegate)方法,您将使用它获取最小和最大 slider 值。

 -(void)rangeSliderTTRangeSlider *)sender didChangeSelectedMinimumValuefloat)selectedMinimum andMaximumValuefloat)selectedMaximum{

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

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

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

 }

关于ios - 如何获得范围 slider 中的最终值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53589611/






欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) Powered by Discuz! X3.4