我实际上试图将用户设置保存在 plist 中,以便我可以从任何地方访问它们。但是当将 UISlider 值保存到我的数组时,我总是会收到消息
将“float”发送到不兼容类型“id”的参数;
数组看起来像这样:
NSArray *value = [[NSArray alloc] initWithObjects: [theGradeSlider value], [theBackgroundSound isOn], [theButtonSound isOn], nil];
我也尝试过使用 MSMutableArray 但这也不起作用....
另一种解决方案
我尝试使用 NSUserDefaults 知道它并且它有效。
保存设置(应插入 viewDidUnload 或 viewDidDiassappear):
NSUserDefaults *settings = [[NSUserDefaults alloc] initWithUser:@"User"];
[settings setFloat:theGradeSlider.value forKey:@"theGradeSlider"];
[settings setBool:theBackgroundSound.on forKey:@"theBackgroundSound"];
[settings setBool:theButtonSound.on forKey:@"theButtonSound"];
[settings synchronize];
加载设置(应插入 viewDidLoad 或 ViewDidAppear):
NSUserDefaults *settings = [[NSUserDefaults alloc] initWithUser:@"User"];
theGradeSlider.value = [settings floatForKey:@"theGradeSlider"];
theBackgroundSound.on = [settings boolForKey:@"theBackgroundSound"];
theButtonSound.on = [settings boolForKey:@"theButtonSound"];