可能重复: 如何成功写入 plist?
我正在尝试写入 test.plist 文件,该文件存储在我的支持文件中,这是我的代码
- (IBAction)acceptAction:(id)sender {
NSBundle *mainBundle = [NSBundle mainBundle];
NSString *pathToFile = [mainBundle pathForResource:@"test" ofType:@"plist"];
NSMutableDictionary *md = [[NSMutableDictionary alloc] initWithContentsOfFile:pathToFile];
[md setValue:@"yes" forKey:@"hasAgree"];
[md writeToFile:pathToFile atomically:YES];
}
- (IBAction)declineAction:(id)sender {
NSBundle *mainBundle = [NSBundle mainBundle];
NSString *pathToFile = [mainBundle pathForResource:@"test" ofType:@"plist"];
NSMutableDictionary *md = [[NSMutableDictionary alloc] initWithContentsOfFile:pathToFile];
NSString *value;
value = [md objectForKey:@"hasAgree"];
NSLog(@"value is %@", value);
}
接受用于写入的操作按钮..拒绝用于阅读的操作按钮..但根本不起作用,有什么建议吗?