如何让滑块逐步浏览阵列?现在他们被设置为测试只是为了显示数字。
@implementation ViewController
- (IBAction)shapeSlider:(id)sender {
UISlider *slider = (UISlider *)sender;
float val = slider.value;
self.shapeLabel.text = [NSString stringWithFormat:@"%f",val];
}
- (IBAction)colorSlider:(id)sender {
UISlider *slider2 = (UISlider *)sender;
float val = slider2.value;
self.colorLabel.text = [NSString stringWithFormat:@"%f",val];
}
- (IBAction)cutSlider:(id)sender {
UISlider *slider3 = (UISlider *)sender;
float val = slider3.value;
self.cutLabel.text = [NSString stringWithFormat:@"%f",val];
}
- (IBAction)PriceSlider:(id)sender {
UISlider *slider4 = (UISlider *)sender;
NSInteger val = lround(slider4.value);
self.priceLabel.text = [NSString stringWithFormat:@"$%d",val];
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[[self zipCode] resignFirstResponder];
return YES;
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[[self view] endEditing:YES];
}
- (void)viewDidLoad
{
[ super viewDidLoad];
// set price slider values
self.priceSlider.minimumValue = 1000;
self.priceSlider.maximumValue = 200000;
// create Arrays
self.shapes = @[@"Round", @"Princess", @"Emerald", @"Asscher", @"Marquise", @"Oval", @"Radiant", @"Pear", @"Heart", @"Cushion"];
self.colors = @[@"J", @"I", @"H", @"G", @"F", @"E", @"D"];
我尝试了很多东西,但似乎很多帖子都很旧,Xcode 5不接受任何恶作剧。
我还需要使用用户选择的任何内容并使用提交按钮发布到电子邮件。如果没有用户在他们的iOS设备上设置邮件,这可能吗?
答案 0 :(得分:0)
根据我在stackoverflow.com上找到的不同答案,以下代码完美运行
- (IBAction)shapeSlider:(id)sender {
UISlider *slider = (UISlider *)sender;
NSInteger sliderValue = (NSInteger)slider.value;
self.shapeLabel.text = [NSString stringWithFormat:@"%@",[_shapes objectAtIndex:sliderValue]];
基本上,滑块必须具有最大值和最小值以及其中具有相同字符串最大值的Array。