Reputation: 61
I am working from a template project and I now have to add a uislider, I want to be able to programatically program the values from my ui slider from a class that is already set up called Price delegate. When I'm researching this I keep coming back with JQuery? can I only do it using jQuery?
I need the closed to read in from the price delegate here is my minimum slider code
- (IBAction)slider:(id)sender {
UISlider *slide = (UISlider *)sender;
int min = (int)(slide.value);
//Display min price
NSString *minprice = [NSString stringWithFormat:@"%d", min];
NSLog(@"min : %@",minprice);
label_min.text = minprice;
NSString * priceString = [[NSString alloc] initWithFormat:@"%@",
[priceDelegate.values objectAtIndex: [_appDelegate int_minPriceV]]];
[self.tf_price setText:priceString];
}
and here is the values I would like the slider to read from
-(void) loadData{
NSArray* array = [[NSArray alloc] initWithObjects:
NSLocalizedString(@"No Min", nil),
@"50,000",
@"100,000",
@"150,000",
@"200,000",
@"250,000",
@"300,000",
@"350,000",
@"400,000",
@"450,000",
@"500,000",
@"550,000",
@"600,000",
@"650,000",
@"700,000",
@"750,000",
@"800,000",
@"850,000",
@"900,000",
@"950,000",
@"1,000,000",
@"1,250,000",
@"1,500,000",
@"1,750,000",
@"2,000,000",
@"3,000,000",
@"4,000,000",
nil];
self.values = array;
[array release];
How to do it or what way to head?
Upvotes: 1
Views: 2807
Reputation: 318954
This is actually pretty simple once you know what to do. Set your slider's range to be from 0.0 to 1.0 (the default).
Now your slider action method becomes:
- (IBAction)slider:(UISlider *)slider {
CGFloat value = slider.value;
NSUInteger index = value * (self.values.count - 1);
NSString *priceString = self.values[index];
// Do what you need with priceString
}
Upvotes: 3