我怎样才能保存UISlider的值?我试过这个,但它不起作用:
-(IBAction)save {
slider1i = slider1.value;
NSUserDefaults *slider1save = [NSUserDefaults standardUserDefaults];
[slider1save setInteger:slider1i forKey:@"slider1key"];
[slider1save synchronize];
}
slider1i
是NSinteger,slider1
是UISlider ...
你能帮我吗?
答案 0 :(得分:1)
正如用户698952所说,UISlider的value属性是浮动的。但我会像这样使用setFloat:
slider1i = slider1.value;
NSUserDefaults *slider1save = [NSUserDefaults standardUserDefaults];
[slider1save setFloat:slider1i forKey:@"slider1key"];
[slider1save synchronize];
答案 1 :(得分:0)
slider1.value
是float
值,所以你首先需要在NSString或NSNumber中转换它以便保存它.....使它成为一个对象
-(IBAction)save {
NSNumber *sliderValue = [NSNumber numberWithFloat:slider1.value];
NSUserDefaults *slider1save = [NSUserDefaults standardUserDefaults];
[slider1save setObject:sliderValue forKey:@"slider1key"];
[slider1save synchronize];
}
感谢