【问题标题】:Write in .plist file iphone/ipad?写入 .plist 文件 iphone/ipad?
【发布时间】:2011-05-03 14:23:45
【问题描述】:
    <dict>
        <key>Name</key>
        <string>Ramesh</string>
        <key>Address</key>
        <string>Delhi</string>
    </dict>

如何在我的 plist 文件中以及在运行时在任何特定的父标记中编写它。

【问题讨论】:

  • 你有 plist 还是写信给 NSUSerDefaults?

标签: iphone ipad plist


【解决方案1】:

只是设置了这个字典,这就是将plist写入apps目录的方法。

NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys:@"Name", @"Ramesh", @"Address", @"Delhi", nil];

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"dictionary.plist"];
[dictionary writeToFile:path atomically:YES];

【讨论】:

  • 此代码正在运行,但无法在 dictionary.plist 文件中写入数据。你能帮我为什么它没有在 .plist 文件中添加数据吗?谢谢。
  • 对我来说效果很好。把文档写在iPhone模拟器的文档目录下就好了。
  • 您尝试写入无法放入 plist 的数据也可能是一个问题。 Plist 仅限于字符串、数字、数组和字典。
猜你喜欢
  • 2012-03-09
  • 1970-01-01
  • 2011-02-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-04-03
  • 1970-01-01
  • 2011-07-23
相关资源
最近更新 更多