iphone - writeToFile 未将新条目保存到 plist 中
我的 writeToFile 没有将我的数据保存到我的 .plist 中。
- (IBAction)clickBtnDone:(id) sender {
NSLog(@"Done");
if ([txtGroupName.text length] > 0) {
[self dismissModalViewControllerAnimated:YES];
NSLog(@"Group Name: %@", txtGroupName.text);
NSMutableArray *newDict = [[NSMutableArray alloc] init];
[self.groups setObject:newDict forKey:txtGroupName.text];
NSLog(@"Count:%d", [self.groups count]);
BOOL success = [self.groups writeToFile:self.groupPath atomically:YES];
if(success) {
NSLog(@"Success Saving New Group");
} else {
NSLog(@"Failure Saving New Group");
}
[newDict release];
}
}
以下是调试显示的内容:
2010-07-01 00:48:38.586 Contacts[7111:207] Done
2010-07-01 00:48:38.589 Contacts[7111:207] Group Name: C
2010-07-01 00:48:38.590 Contacts[7111:207] Count:3
2010-07-01 00:48:38.592 Contacts[7111:207] Success Saving New Group
但是,当我打开 .plist 文件时,它仍然只有我手动创建的 2 个组,而不是新条目。
这些文件位于我的 ~Documents 文件夹中。
有什么想法吗?
My writeToFile is not saving my data to my .plist.
- (IBAction)clickBtnDone:(id) sender {
NSLog(@"Done");
if ([txtGroupName.text length] > 0) {
[self dismissModalViewControllerAnimated:YES];
NSLog(@"Group Name: %@", txtGroupName.text);
NSMutableArray *newDict = [[NSMutableArray alloc] init];
[self.groups setObject:newDict forKey:txtGroupName.text];
NSLog(@"Count:%d", [self.groups count]);
BOOL success = [self.groups writeToFile:self.groupPath atomically:YES];
if(success) {
NSLog(@"Success Saving New Group");
} else {
NSLog(@"Failure Saving New Group");
}
[newDict release];
}
}
Here is what the debug shows:
2010-07-01 00:48:38.586 Contacts[7111:207] Done
2010-07-01 00:48:38.589 Contacts[7111:207] Group Name: C
2010-07-01 00:48:38.590 Contacts[7111:207] Count:3
2010-07-01 00:48:38.592 Contacts[7111:207] Success Saving New Group
However, when I open the .plist file, it still has only 2 groups that I had created manually, and not the new entry.
The files are located in my ~Documents folder.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你是如何初始化groupPath的?它应该是文档目录的路径,而不是资源目录的路径。
您应该执行类似的操作:
您无法编辑工作区中存在的文件。
How you have initialized groupPath? It should be the path of document directory, not the path of resource directory.
You should do something similar :
You can not edit the file that is present in the workspace.