我有这个问题。我有一个名为'instellingen'的plist文件。在文件中,存储了不同的设置。例如,在启动时显示游戏规则。这在模拟器上运行得很好但是当我在iPad上测试时,plist dat不会被保存。
这是我的代码:
- (void)viewDidLoad
{
[super viewDidLoad];
plistPath = [[NSBundle mainBundle] pathForResource:@"instellingen" ofType:@"plist"];
instellingen = [NSMutableDictionary dictionaryWithContentsOfFile:plistPath];
if ([[instellingen objectForKey:@"regelAtRuntime"] boolValue] == TRUE) {
[self.showRulesButton setTitle:@"Spelregels niet meer tonen" forState:UIControlStateNormal];
}else{
[self.showRulesButton setTitle:@"Spelregels wel tonen" forState:UIControlStateNormal];
}
[self.mainContent flashScrollIndicators];
}
- (IBAction)dismissRules:(id)sender {
[self dismissViewControllerAnimated:YES completion:nil];
}
- (IBAction)dontShowRegels:(id)sender {
if ([[instellingen objectForKey:@"regelAtRuntime"] boolValue] == TRUE) {
[instellingen setValue:@"0" forKey:@"regelAtRuntime"];
}else{
[instellingen setValue:@"1" forKey:@"regelAtRuntime"];
}
[instellingen writeToFile:plistPath atomically:YES];
}
从可怕的租金VC中读取规则似乎工作得很好,有这样的代码:
NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"instellingen" ofType:@"plist"];
instellingen = [NSDictionary dictionaryWithContentsOfFile:plistPath];
if ([[instellingen objectForKey:@"regelAtRuntime"] boolValue] == TRUE) {
NSLog(@"We're in!");
[self performSegueWithIdentifier:@"showRulesSegue" sender:self];
}
有谁知道我做错了什么?我尝试过运行干净的构建(Product Clean)。
任何帮助都意味着很多!
答案 0 :(得分:1)
应用程序包在Simulator上是可读写的,但在设备上是只读的。首次启动应用程序时,应将plist复制到Documents目录(如果需要备份)或Library / Caches(如果没有),然后在应用程序中使用该版本。