0

我之前问过这个问题,我相信我问错了,所以我会更清楚。答案是非常周到和有用的,再一次。我想在我的 IOS Xcode 中知道...我有一个主/详细视图模板。我正在使用捆绑包中的 Plist 加载主表视图,但我正在更新文档文件夹中的 Plist...如何让这些更新反映在捆绑包中,以及如何刷新屏幕。可以的话请指教。先感谢您。问候,

这是我加载主表的代码...看起来有什么不正确的地方:我正在从 Documents 文件夹加载...但我没有从文档中获取所有记录:

NSLog(@"loading data");
    self.navigationItem.title=@"Accounts";
//    NSString *accountFile = [[NSBundle mainBundle] pathForResource:@"Accounts2" ofType:@"plist"];
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentPath = [paths objectAtIndex:0];
    NSString *plistPath = [documentPath stringByAppendingPathComponent:@"Accounts2.plist"];
    accounts = [[NSMutableDictionary alloc] initWithContentsOfFile:plistPath];
    account = [accounts objectForKey:@"Account"];
    number = [accounts objectForKey:@"Number"];
    dueDay = [accounts objectForKey:@"DayDue"];
    minAmount = [accounts objectForKey:@"MinAmount"];
    balance = [accounts objectForKey:@"Balance"];

    NSLog(@"data loaded");

    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    self.navigationItem.leftBarButtonItem = self.editButtonItem;

    UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(insertNewObject:)];
    self.navigationItem.rightBarButtonItem = addButton;
4

1 回答 1

0

您无法更新应用程序包中的任何内容。它是只读的(至少在真实的 iOS 设备上)。

您必须从文件夹等可写位置对 plist 文件进行所有读取和写入操作Documents。第一次尝试访问该文件时,它不存在。解决方案是从应用程序包中复制初始文件。从那时起,您只能读取/写入Documents.

于 2013-06-10T21:38:38.183 回答