在文件目录中找不到plist文件?如何以编程方式修改plist? [英] Can not find plist file in documents directory? How to modify the plist programmatically?

查看:97
本文介绍了在文件目录中找不到plist文件?如何以编程方式修改plist?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Xcode 4.2中有一个应用程序.

I have an application in Xcode 4.2.

我已根据需要创建了plist文件.

I have created plist file as my requirement.

我从Applications主捆绑包中找到了数据,并将数据放入了阵列中.

I have found the data from Applications main bundle and got the data in to the array.

但是,由于我想在运行时修改plist数据,因此无法在Documents Directory中找到它

But As I want to modify the plist data at run time, I could not find it in Documents Directory

实际上,我想以编程方式修改plist.虽然我没有使用mainbundle.

Actually I want to modify the plist programmatically. Though I am not using mainbundle.

-(NSString *) saveFilePath::(NSString *)tagString     
{
    NSArray *arr = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

    NSString *strPath = [[arr objectAtIndex:0] stringByAppendingPathComponent:tagString];       
    return strPath;
} 

无法检索plist文件.(我正在获取路径,但文件未获取路径)

Could not retrive the plist file.(Path I am getting, but path with file not getting)

我还无法在iphone模拟器/App/Documents文件夹中找到plist文件吗?

I also could not find physically the plist file in the iphone simulator/App/Documents folder?

推荐答案

您需要先将plist从分发包复制到文档目录

you need to copy plist from bundle to document directory first

-(void) checkAndCreateSetting
{
    BOOL success;
    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSError *error;
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *writableDBPath= [documentsDirectory stringByAppendingPathComponent:@"Settings.plist"];
    success = [fileManager fileExistsAtPath:writableDBPath];
    if (success) return;
    // The writable database does not exist, so copy the default to the appropriate location.
    NSString *defaultDBPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Settings.plist"];
    success = [fileManager copyItemAtPath:defaultDBPath toPath:writableDBPath error:&error];
    if (!success) {
        NSAssert1(0, @"Failed to create writable database file with message '%@'.", [error localizedDescription]);
    }
}

如有任何查询,请通知我 谢谢问候 尼尔

let me know in case of any query thanks& regards neil

这篇关于在文件目录中找不到plist文件?如何以编程方式修改plist?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆