I’m making a search function in my app but I’m having some trouble figuring the codes for my UISlider. Slider is created in the storyboard and hooked up. I have a .plist with an array of dictionaries as info source. The dictionaries are containing info about wines.
-
Slider should reprecent the values of the key “Price” in the dictionaries. I chose Number for it, so some of them are like 78,900000000001. In other words they need format with two decimals.
-
minimumValue = the lowest value in the dictionaries, rounded down to closest 10 (if lowest value = 67,90 then minimumValue = 60) if that’s not too complicated.
-
maximumValue = highest value but rounded up to closest 10.
-
It is for user to set an optional minimum price, so default position should be minimumValue.
-
I want it to step by 5 numbers at the time when slided, like 70, 75, 80, 85, 90 etc
This is the codes for the UISlider so far:
- (void)viewDidLoad
{
[super viewDidLoad];
self.navigationItem.title = @"Search";
NSString *path = [[NSBundle mainBundle] pathForResource:@"Wines" ofType:@"plist"];
allObjectsArray = [[NSMutableArray alloc] initWithContentsOfFile:path];
minSlider.continuous = YES;
[minSlider setMinimumValue: ]; // Lowest value rounded down to closest 10
[minSlider setMaximumValue: ]; // Highest value rounded up to closest 10
[minSlider addTarget:self
action:@selector(minValueChanged:)
forControlEvents:UIControlEventValueChanged];
minText.text = minSlider.minimumValue // <--- or something like that
}
- (void)minValueChanged:(UISlider*)sender
{
// And something here for change of value and text field
minText.text = current slider value
}
Can you help me finish this? I’ve started up based on what I learned from my research before asking. 🙂
It depends a bit on how your plist is structured, but you are not telling us… I am assuming it looks something like
This is how you determine the minimum and maximum values:
This is how you round the numbers:
This is how you set the slider minimum value:
This is how you make a label display only multiples of 5: